Php pointer extraction

Source: Internet
Author: User
Php pointer references the features of PHP pointer: 1. use & amp; to pass the address of the variable to another variable. in this way, the other variable points to the same address 2, $ c $ p is used; $ p is the pointer, and a value like this is actually equivalent to making $ c reference the variable referred to by $ p, instead of Address 3, the normal number is to pass the reference of a variable to another variable. if the content of the source variable remains unchanged, the content of the variable that references it will not change, php pointer reference when no variable content is modified

PHP pointer features:


1. use = & to pass the variable address to another variable. in this way, the other variable points to the same address.


2. use $ c = $ p. where $ p is the pointer. a value like this is actually equivalent to making $ c reference the variable referred to by $ p, not the address.


3. the normal = sign is to pass the reference of a variable to another variable. if the content of the source variable remains unchanged, the content of the variable that references it will not change, that is, when the variable content is not modified, the two variables point to the same address, but when the source variable is modified, the variables that reference it copy the content of the source variable and place it in a new memory address. the variables that reference it point to the newly created memory address, an overview of a simple sentence is: copy when modifying


4. so, return to (2). If the content pointed to by $ p changes, a copy of the original $ p content will be automatically copied to a new memory address, when $ c is output using echo, the output content is still the content before $ p is changed.


5. to sum up, you can export data (and it has been proved by experiments). if $ a, $ B = & $ a, when you modify, the content of B will also change. if you want to reference B with c and it will also affect c when a changes, you must write as follows:
???? $ A = "aa ";
???? $ B = & $;
???? $ C = & $ B;
???? In this case, when a changes, the result of outputting B and c with echo is the same as that of a. of course, this is to illustrate the features of php pointers, he does not specifically want to explain how to use php in a specific application, just to have a deeper understanding of php pointers.
???? If the last line of the above three lines of code becomes: $ c = $ B;


???? When a changes, the output value of c is still the original value of.

?

Source: http://www.phper.org.cn /? Posting = 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.