如果你希望一个函数参数意志通过引用被传递,你可以预先函数定义中在参数名前加符号(&):
function foo( &$bar ) {
$bar .= @# and something extra.@#;
}
$str = @#This is a string, @#;
foo ($str);
echo $str; // 输出 @#This is a string, and something extra.@#
如果你希望向一个不是用这种方式定义的函数用调用的方式传递参数,你可以在函数调用中的参数名称前加符号(&).
function foo ($bar) {
$bar .= @# and something extra.@#;
}
$str = @#This is a string, @#;
foo ($str);
echo $str; //输出 @#This is a string, @#
foo (&$str);
echo $str; //输出 @#This is a string, and something extra.@#
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/










