php按引用传参

来源:互联网 发布:淘宝主营怎么修改 编辑:程序博客网 时间:2024/05/17 22:05

传递方式

调用函数func($str)

定义函数function func(&$str)


注意使用方式!

使用错误会提示:Call-time pass-by-reference has been removed....


看一段别人的例子:

<?php

functionadd_some_extra(&$string) // 引入变量,使用同一个存储地址

{

$string .='and something extra.';

}

$str ='This is a string, ';

add_some_extra($str);

echo $str; // outputs 'This is a string, and something extra.'

}

?>

输出结果:This is a string,and something extra.


<?phpfunctionadd_some_extra($string){

$string .= 'and something extra.';

}

$str = 'This is a string, ';

add_some_extra($str);

echo $str; // outputs 'This is a string, '?>


输出结果:This is a string,