PHP pointer reference
PHP's pointers are characterized by:
1, use =& to pass the address of the variable to another variable, so that the other variable points to the same address
2, with $c= $p; where $p is a pointer, an assignment like this is actually the equivalent of letting $c refer to the variable that the $p refers to, not the address
3, the normal = number is a reference to a variable to another variable, if the content of the source variable is not changed, then the contents of the variable referencing it will not change, that is, when the variable content is not modified, two variables are pointing to the same address, but when the source variable is modified, The variable that references it will copy the contents of the source variable and put it in a new memory address, and the variable referencing it is pointing to the newly created memory address, with a simple sentence: copy on change
4, so, back to (2), if the content of the $p point has changed, then, will automatically copy a copy of $p original content to a new memory address, when the echo output $c, the output content is $p content changes before the content.
5, in summary, can be pushed to export (and also through experimental proof), if there is a $ A, $b =& $a, then you modify a, B's content will also change, if you want to use C to reference B, and a change can also affect C, then you must write as follows:
???? $a = "AA";
???? $b =& $a;
???? $c =& $b;
???? So, when a changes, with the Echo output B and C are the same as the content of a, of course, this is to illustrate the characteristics of the PHP pointer, do not specifically want to explain what he will use in the specific application, just for a deeper understanding of PHP pointers.
???? If the last line of three lines of code above becomes: $c = $b;
???? Then, when a changes, the value of output C is still the original value of a.
?
Source: http://www.phper.org.cn/?post=120