PHP pointer quote

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.