php 奇怪现象,求大神解答

WBOY
发布: 2016-07-29 09:14:18
原创
998 人浏览过
<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></h3></span><span color: background-color:>原来数据</span><span>"</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></h3></span><span color: background-color:>加入</span><span>dept</span><span color: background-color:>后</span><span>"</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></h3></span><span color: background-color:>重新遍历</span><span>"</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></span>
登录后复制

输出:

原来数据

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教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!