Reference: It means passing the address of the original object in memory to the target object, which is equivalent to the original object and the target object pointing to the same memory address. At this time, if the target object or the original object is modified, the data in the memory will also change.
The so-called value transfer means that only passing the value of the object to the target object is equivalent to copying; the system will re-open an identical memory space for the target object.
The so-called reference means passing the address of the object in memory to the target object, which is equivalent to making the target object and the original object correspond to the same memory storage space. At this time, if the target object is modified, the data in the memory will also change.
When passing a value, if it is a non-object, a copy of the value will be passed. Any changes to this variable will not affect the original value. Passing a reference or object means passing the real memory address. Changes to this variable will affect the original value.
The code is as follows
|
Copy code
|
||||
| function func1($a)
function func2(&$a)
9.echo $sample; // Output 2