Php array reference

Source: Internet
Author: User
{Code ...}
Php$ A = array (1); $ B = & $ a [0]; // comment out the statement and Output 2, 1 $ c = $ a; $ c [0] ++; echo $ c [0]. $ a [0]; // outputs comments to the second statement, and outputs.

Reply content:
Php$ A = array (1); $ B = & $ a [0]; // comment out the statement and Output 2, 1 $ c = $ a; $ c [0] ++; echo $ c [0]. $ a [0]; // outputs comments to the second statement, and outputs.

Http://php.net/manual/en/language.references.whatdo.php

Note, however, that references inside arrays are potentially dangerous. doing a normal (not by reference) assignment with a reference on the right side does not turn the left side into a reference, but references inside arrays are preserved in these normal assignments. this also applies to function cballs where the array is passed by value.

When assigning values to an array, if the data on the right is referenced, the elements corresponding to the new array assigned to the value are also referenced, therefore, changing the value of $ c [0] also changes the value of $ a [0.

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.