PHP strange phenomenon, ask the big God solution

Source: Internet
Author: User
  $aBU= Array(Array( ' id '=' 0 ', ),Array( ' id '=' 1 ', ),Array( ' id '=' 2 ', ),Array( ' id '=' 3 ', ),);Echo"

Original data

";Print_r ($aBU);Echo" ";foreach($aBU as&$bu){$bu[' Dept '] = rand ( -, 999);}//unset ($BU);Echo"

Join Dept after

";Print_r ($aBU);Echo" ";Echo"

Re-traverse

";foreach($aBU as$key=$bu){Print_r ($bu);Echo"
";}

Output:

Original data

Array ([0] = = Array ([id] = 0) [1] = = Array ([ID] + 1) [2] = = Array ([ID] + 2) [3] = = Array ([id] = 3))

After joining Dept

Array ([0] = = Array ([id] = 0 [Dept] = 783) [1] = = Array ([id] = 1 [Dept] = 683) [2] = = Array ([id] = 2 [Dept] = 442) [3] = = Array ([id] = 3 [Dept] + 121))

Re-traverse, the last element unexpectedly get is actually a previous element?

Array ([id] = 0 [Dept] = 783)
Array ([id] = 1 [Dept] = 683)
Array ([id] = 2 [Dept] = 442)
Array ([id] = 2 [Dept] = 442)

The above introduces the strange phenomenon of PHP, ask God to answer, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.