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工作仍然正常
?> 

posted @ 2014-05-09 11:32  一束光  阅读(166)  评论(0编辑  收藏  举报

友情链接

CFC4N