Home >Backend Development >PHP Tutorial >The difference between passing parameters and passing addresses in PHP_PHP Tutorial

The difference between passing parameters and passing addresses in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 09:56:15858browse

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

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

This article mainly introduces the difference between value-passing and address-passing in PHP parameter passing. It is very simple. You can understand it through a simple comparison with examples. Friends in need can refer to it.

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

 ?

1

2

3

function test(&val){

return $val;

}

1

2

3

1

2

3

4

5

6

7

$test = "hello";

function myFun(&$val){

$val = "hello world";

return $val;

}

echo myFun(&$test); //hello world

echo $test; //hello world

function test(&val){

return $val; }

Passing by address means allowing changes within the function, such as:  ?
1 2 3 4 5
6 7
$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. http://www.bkjia.com/PHPjc/989554.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/989554.htmlTechArticleThe difference between value-passing and address-passing in PHP parameter-passing. The difference between value-passing and address-passing in PHP parameter passing. The article mainly introduces the difference between passing parameters in PHP by value and passing by address. It is very simple. You can simply use examples...
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