改变给定值的php函数参数
我是php新手,我正在尝试完成以下任务。我的任务是完成丢失的代码。任何人都可以帮助我为什么函数没有返回我希望它返回的内容,以及任何关于如何重构代码的建议都将不胜感激。正如我提到的,我不允许更改给定的部分代码作业:您的任务是完成以下程序,以便按示例所示进行打印。您只需要编写一个缺少的函数。只需在文本框中编写缺少的函数。不完整的程序改变给定值的php函数参数,php,Php,我是php新手,我正在尝试完成以下任务。我的任务是完成丢失的代码。任何人都可以帮助我为什么函数没有返回我希望它返回的内容,以及任何关于如何重构代码的建议都将不胜感激。正如我提到的,我不允许更改给定的部分代码作业:您的任务是完成以下程序,以便按示例所示进行打印。您只需要编写一个缺少的函数。只需在文本框中编写缺少的函数。不完整的程序 <?php // Your code here $charstring = "first\n"; newvalue(
<?php
// Your code here
$charstring = "first\n";
newvalue($charstring);
echo "String in the end: $charstring\n";
?>
Example output
String in the start: first
String in the end: New string
现在,您必须更新
$charstring
变量,然后返回它
<?php
function newvalue($charstring){
global $charstring;
echo "String in the start: $charstring <br />";
//If you are using a browswer, you must use a <br /> tag to get a new line,
// if you aren't using a browser than remove it
$charstring = "New String";
return $charstring;
}
$charstring = "first\n";
newvalue($charstring);
echo "String in the end: $charstring\n";
/*
Example output
String in the start: first
String in the end: New string
*/
?>
这应该会有帮助:我认为它被称为通过引用传递…和$charstring
如果我在处理任务时出错或遗漏了一些东西,我只需要一些建议?问错了吗,先生?你可以在手册和其他地方看到一些例子。
<?php
function newvalue($charstring){
global $charstring;
echo "String in the start: $charstring <br />";
//If you are using a browswer, you must use a <br /> tag to get a new line,
// if you aren't using a browser than remove it
$charstring = "New String";
return $charstring;
}
$charstring = "first\n";
newvalue($charstring);
echo "String in the end: $charstring\n";
/*
Example output
String in the start: first
String in the end: New string
*/
?>