cundeng 发表于 2017-3-3 10:46:15

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工作仍然正常
?>
页: [1]
查看完整版本: php引用