确实的foreach()用于非数字数组键的工作? [英] Does foreach() work for non-numerical array keys?
本文介绍了确实的foreach()用于非数字数组键的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在想,如果的foreach()的作品当数组是这样的:
I was wondering if foreach() works when the array looks like this:
- arr_name [鸡蛋] =东西
- arr_name [铅笔] =别的什么
会的foreach的工作,如果运行的是:
Will foreach work if run as:
foreach(arr_name as $key => $value)
对于具有非数值他们的钥匙?
for they keys that have a non-numerical value ?
推荐答案
是的foreach
支持任何形式的密钥。在你的情况, $键
将是一个字符串,'蛋'
和'铅笔'
分别为每个项目。事实上,旨在为使用具有非数字键阵列的foreach
,你不能轻易使用迭代为
。
Yes, foreach
supports any kind of key. In your case, $key
will be a string, 'eggs'
and 'pencil'
respectively for each item. In fact, foreach
was intended for use with arrays that have non-numerical keys which you can't easily iterate using for
.
这篇关于确实的foreach()用于非数字数组键的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文