The reference of complex arrays is not recommended in the PHP Manual. what should I do?-php Tutorial

Source: Internet
Author: User
The reference to complex arrays is not recommended in the PHP Manual. The following is the original article in the manual: it is best to copy complex arrays rather than reference them. The following example will not work as expected. PHPcode & lt ;? Php $ toparray (A & gt; array (), B & gt; array (B _ B & gt; array (),); $ to the PHP Manual, the reference of complex arrays is not recommended.
The original text in the manual is as follows:

It is best to copy complex arrays rather than reference them. The following example will not work as expected.
PHP code
  
   array(),    'B' => array(        'B_b' => array(),    ),);$top['A']['parent'] = &$top;$top['B']['parent'] = &$top;$top['B']['B_b']['data'] = 'test';print_r($top['A']['parent']['B']['B_b']); // array()?> 


The output result is Array ([data] => test). isn't that expected?
$ Top ['A'] ['parent'] is A reference to the $ top variable ($ top ['A'] ['parent'] = & $ top ;)
Under it ['B'] ['B _ B'],
Isn't it defined by $ top ['B'] ['B _ B'] ['data'] = 'test'; [data] => test?
How can I work as expected? What should I do?

------ Solution --------------------
Let's take a look at the php reference transfer address!
------ Solution --------------------
Output the structure of each step to make it clear:

PHP code
$top = array(            'A' => array(),            'B' => array(                'B_b' => array(),            ),        );        $top['A']['parent'] = &$top;        echo '
';        print_r($top['A']['parent']);        echo '
'; echo '
';        $top['B']['parent'] = &$top;        echo '
'; echo '
';        print_r($top['B']['parent']);        echo '
'; echo '
';        $top['B']['B_b']['data'] = 'test';        print_r($top['B']['B_b']);        echo '
'; echo '
';        print_r($top['A']['parent']['B']['B_b']); // array()        echo '
'; echo '
';

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.