Home >Backend Development >PHP Tutorial >The difference between passing parameters in PHP by value and passing address, passing parameters in php_PHP tutorial

The difference between passing parameters in PHP by value and passing address, passing parameters in php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 09:56:191128browse

The difference between value-passing and address-passing in PHP parameter passing, PHP parameter passing

Without further ado, let’s look at the code first

function test(&val){
return $val;
}

Why is & used to pass parameters? What are the benefits?

Passing by address means allowing changes within the function, for example:

$test = "hello";
function myFun(&$val){
$val = "hello world";
return $val;
}
echo myFun(&$test); //hello world
echo $test;         //hello world

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/989569.htmlTechArticleThe difference between value-passing and address-passing in PHP parameter passing. Not much nonsense about PHP parameter passing. Let’s look at the paragraph first. Code function test(} Why is function myFun(return $val;}echo myFun( //hello worldecho...
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