PHP通过引用传递参数


<?php
function add_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.

如果没有这个&符号,

<?php
function add_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,


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM