关于PHP手册中,不推荐复杂数组的引用举的一个例子,不解
下面是手册里的原文:
复杂数组最好拷贝而不是引用。下面的例子不会如期望中那样工作。
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php$top = array( 'A' => 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()?>
$top = array( 'A' => array(), 'B' => array( 'B_b' => array(), ), ); $top['A']['parent'] = &$top; echo '<pre class="brush:php;toolbar:false">'; 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 '
';<div class="clear"></div>