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

WBOY
Release: 2016-07-13 09:56:19
Original
1098 people have browsed it

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;
}
Copy after login

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

Copy after login

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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template