Home >php教程 >php手册 >通过调用传递Passingbyreference

通过调用传递Passingbyreference

WBOY
WBOYOriginal
2016-06-13 10:26:251515browse

默认的,函数参数通过值来传递.如果你希望允许一个函数可以修改它的参数的值,你可以通过调用来传递他们.
如果你希望一个函数参数意志通过引用被传递,你可以预先函数定义中在参数名前加符号(&):
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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn