php面试题,请写出以下php代码输出什么?
<?PHPfunction add_some_extra($string){ $string .=...
<?PHP
function add_some_extra($string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str;
?>
上述代码有缺陷吗?有的话该如何改进? 展开
function add_some_extra($string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str;
?>
上述代码有缺陷吗?有的话该如何改进? 展开
2个回答
展开全部
有缺陷。
改前输出:This is a string,
改后输出:This is a string, and something extra.
function add_some_extra($string)
{
$string .= 'and something extra.';
return $string;
}
$str = 'This is a string, ';
$str = add_some_extra($str);
echo $str;
改前输出:This is a string,
改后输出:This is a string, and something extra.
function add_some_extra($string)
{
$string .= 'and something extra.';
return $string;
}
$str = 'This is a string, ';
$str = add_some_extra($str);
echo $str;
追问
嗯嗯
追答
我给你的代码就是改进后的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询