<span><?php </span><span >$aBU </span><span >= </span><span >array </span><span >( </span><span ></span><span >array </span><span >( </span><span >'id' </span><span >=> </span><span>'0'</span><span>, </span><span>)</span><span>, </span><span></span><span>array </span><span>( </span><span>'id' </span><span>=> </span><span>'1'</span><span>, </span><span>)</span><span>, </span><span></span><span>array </span><span>( </span><span>'id' </span><span>=> </span><span>'2'</span><span>, </span><span>)</span><span>, </span><span></span><span>array </span><span>( </span><span>'id' </span><span>=> </span><span>'3'</span><span>, </span><span>)</span><span>, </span><span>)</span><span>; </span><span>echo </span><span>"<h3></span><span color: background-color:>原来数据</span><span></h3>"</span><span>; </span><span>print_r(</span><span>$aBU</span><span>)</span><span>; </span><span>echo </span><span>"<hr />"</span><span>; </span><span></span><span>foreach</span><span>(</span><span>$aBU </span><span>as </span><span>&</span><span>$bu</span><span>){ </span><span></span><span>$bu</span><span>[</span><span>'dept'</span><span>] = rand(</span><span>100</span><span>, </span><span>999</span><span>)</span><span>; </span><span>} </span><span>//unset($bu); </span><span>echo </span><span>"<h3></span><span color: background-color:>加入</span><span>dept</span><span color: background-color:>后</span><span></h3>"</span><span>; </span><span>print_r(</span><span>$aBU</span><span>)</span><span>; </span><span>echo </span><span>"<hr />"</span><span>; </span><span></span><span></span><span>echo </span><span>"<h3></span><span color: background-color:>重新遍历</span><span></h3>"</span><span>; </span><span>foreach</span><span>(</span><span>$aBU </span><span>as </span><span>$key </span><span>=> </span><span>$bu</span><span>){ </span><span> print_r(</span><span>$bu</span><span>)</span><span>; </span><span></span><span>echo </span><span>"<br />"</span><span>; </span><span>}</span>
Ausgabe:
Originaldaten
Array( [0] => Array ( [id] => 0 ) [1] => Array ( [id] => ; 1 ) [2] => Array ( [id] => 2 ) [3] => Array ( [id] => 3 ))Nach dem Hinzufügen von dept
Array( [0] => Array ( [id] => 0 [dept] => 783 ) [1] => Array ( [id] => ; 1 [Abteilung] => 683 ) [2] => Array ( [id] => 2 [Abteilung] => 442 ) [3] => ] => 121 ))Erneut durchlaufen, Das letzte Element hat tatsächlich das vorherige Element erhalten?
Das Obige hat das seltsame Phänomen von PHP eingeführt. Bitten Sie den Master, es zu beantworten, einschließlich des relevanten Inhalts. Ich hoffe, es wird für Freunde hilfreich sein, die sich für PHP-Tutorials interessieren.