The so-called value pass, which means that only the value of the object is passed to the target object, which is equivalent to copy; The system will reopen a completely identical memory space for the target object.
A reference, that is, passing an object's address in memory to the target object is equivalent to having the target object and the original object correspond to the same memory storage space. In this case, the data in memory will change if the target object is modified.
If the value is not an object, a copy of the value will be transmitted, and any changes made to the variable do not affect the original value. Passing the reference or passing the object, is to pass the real memory address, changes to this variable will affect the original value.
| The code is as follows |
Copy Code |
|
function func1 ($a)
{$a = $a + 1;}
function Func2 (& $a)
{$a = $a + 1;}
$sample = 1;
Func1 ($sample);
Echo $sample; Output 1
$sample = 1;
Func2 ($sample);
9.echo $sample; Output 2 |
Summarize
In high school the teacher told us that the reference is to give the memory address to the variable so long as the memory address changes and the contents of our accounting variables will be changed, it's kind of like a house with something that we can all get into, as long as things change. We go in and see things the same, Instead of me holding things in my hand, things change in my room and I don't change.