当前位置:Gxlcms > PHP教程 > php奇怪现象,求大神解答

php奇怪现象,求大神解答

时间:2021-07-01 10:21:17 帮助过:5人阅读

$aBU = array (
array ( 'id' => '0', ),
array ( 'id' => '1', ),
array ( 'id' => '2', ),
array ( 'id' => '3', ),
);
echo "

原来数据

"
; print_r($aBU); echo "
"
; foreach($aBU as &$bu){ $bu['dept'] = rand(100, 999); } //unset($bu); echo "

加入dept

"
; print_r($aBU); echo "
"
; echo "

重新遍历

"
; foreach($aBU as $key => $bu){ print_r($bu); echo "
"
; }

输出:

原来数据

Array( [0] => Array ( [id] => 0 ) [1] => Array ( [id] => 1 ) [2] => Array ( [id] => 2 ) [3] => Array ( [id] => 3 ))

加入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 ))

重新遍历,最后一个元素的竟然得到的竟然是前一个元素?

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

以上就介绍了php 奇怪现象,求大神解答,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行