PHP 3 专题 -- 通过调用传递(Passing by reference)

---摘自互联网

        默认的,函数参数通过值来传递.如果你希望允许一个函数可以修改它的参数的值,你可以通过调用来传递他们. 

        如果你希望一个函数参数意志通过引用被传递,你可以预先函数定义中在参数名前加符号(&): 

function  foo(  &$bar  )  { 

$bar  .=  '  and  something  extra.'; 



$str  =  'This  is  a  string,  '; 

foo  ($str); 

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

        如果你希望向一个不是用这种方式定义的函数用调用的方式传递参数,你可以在函数调用中的参数名称前加符号(&). 

function  foo  ($bar)  { 

$bar  .=  '  and  something  extra.'; 



$str  =  'This  is  a  string,  '; 

foo  ($str); 

echo  $str;  //输出  'This  is  a  string,  ' 

foo  (&$str); 

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