Reference the variable in php to transfer the value learning notes. Reference: it means to pass the address of the original object in the memory to the target object, which means that the original object and the target object point to the same memory address. At this point, if you reference the target object: it means to pass the address of the original object in the memory to the target object, it is equivalent that the original object and the target object point to the same memory address. At this time, if you modify the target object or the original object, the data in the memory will also change.
The so-called value transfer means that only passing the object value to the target object is equivalent to copy; the system will re-open a completely identical memory space for the target object.
The so-called reference means passing the address of the object in the memory to the target object is equivalent to making the target object and the original object correspond to the same memory bucket. At this time, if you modify the target object, the data in the memory will also change.
If a value is passed, if it is not an object, a copy of the value will be sent, and any changes to this variable will not affect the original value. It refers to the memory address of the fax to transmit the reference or object. changes made to this variable will affect the original value.
| The code is as follows: |
|
Function func1 ($) {$ A = $ a + 1 ;} Function func2 (& $) {$ A = $ a + 1 ;} $ Sample = 1; Func1 ($ sample ); Echo $ sample; // output 1 $ Sample = 1; Func2 ($ sample ); 9. echo $ sample; // output 2 |
Summary
In high school, the teacher told us that the reference is to give the memory address to the variable so that as long as the memory address changes, the variable content of our accounting will also change, this is a bit like a house with things. we can all go to get things. as long as things have changed, we can see the same things, rather than holding things in our hands, in this way, the things in the room have changed.
Bytes. In this case, if the target object is...