分类广告


推荐文章

  • 没有找到任何内容!
您当前的位置:中国站长下载网络编程PHP专区 → 文章内容

通过调用传递(Passingbyreference)

  • 作者:佚名    来源:不详    发布时间:2006-2-26 1:30:19
  • 字体大小:
默认的,函数参数通过值来传递.如果你希望允许一个函数可以修改它的参数的值,你可以通过调用来传递他们.

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

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.'
<
上一篇CLASS 下一篇返回值