Home  >  Article  >  Backend Development  >  The difference between passing by value and reference in PHP

The difference between passing by value and reference in PHP

(*-*)浩
(*-*)浩Original
2019-10-12 15:05:492867browse

The difference between passing by value and reference in PHP

Passing value

Passing value is to copy the value of the variable to a new value (the value is the same ), only two different memory spaces appear in the memory. Assign the new value memory space address to the new variable name. Modifying the values ​​of the two variables has no effect. (Recommended learning: PHP video tutorial)

$a1 = 234;
$a2 = 34556;
$a1 = $a2;
var_dump($a1,$a2);
$a2 = 'nongjiale.fun';
var_dump($a1,$a2);

Quote

Quote is to copy the reference of the variable (new The reference still points to the original value).

$y1 = 23;
$y2 = 433;
var_dump($y1,$y2);//输出int 23 int 433
$y2 = &$y1;
$y2 = 'mudidi.tech';
var_dump($y1,$y2);//输出string 'mudidi.tech' string 'mudidi.tech'

The above is the detailed content of The difference between passing by value and reference in PHP. For more information, please follow other related articles on the PHP Chinese website!

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