php引用详解

<?php
function foo($bar){
  $bar=‘111111111‘;
}

$str=‘2222222222222‘;
foo($str);
echo $str; //output is 2222222222222

$str2=‘xxxxxxxxxxxx详详细细2222222222222‘;
foo(&$str2);
echo $str2; //output is 111111111
//即使函数的参数定义不是&$arg,引用传过去也能修改原值

function foo(&$bar){
  $bar=‘111111111‘;
}
$str=‘2222222222222‘;
foo($str);
echo $str; //output is 111111111
$str2=‘xxxxxxxxxxxx详详细细2222222222222‘;
foo(&$str2);
echo $str2; //output is 111111111
//函数定义了&arg参数,传的时候使用&$arg工作仍然正常
?> 

php引用详解,布布扣,bubuko.com

文章来自:http://www.cnblogs.com/Alight/p/3718551.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3