Home  >  Article  >  Backend Development  >  Passing by reference_PHP tutorial

Passing by reference_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:26:21968browse

By default, function arguments are passed by value. If you wish to allow a function to modify the values ​​of its arguments, you can pass them by calling them.
If you want a function argument to be passed by reference, you can prepend Add the ampersand (&) before the parameter name in the function definition:
function foo( &$bar ) {
$bar .= and something extra.;
}
$str = This is a string, ;
foo ($str);
echo $str; // Output This is a string, and something extra.
If you want to pass a call to a function that is not defined this way Parameters, you can add the ampersand (&) before the parameter name in the function call.
function foo ($bar) {
$bar .= and something extra.;
}
$str = This is a string, ;
foo ($str);
echo $str; //output This is a string,
foo (&$str);
echo $str; //output This is a string, and something extra.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531960.htmlTechArticleBy default, function parameters are passed by value. If you want to allow a function to modify the value of its parameters, You can pass them by calling. If you want a function parameter will...
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