用php获取多维数组中父数组键的最快方法 [英] fastest way to get parent array key in multidimensional arrays with php
本文介绍了用php获取多维数组中父数组键的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用多维数组获取父数组键的最佳方法是什么? 例如,我有这个数组:
what is the best way to get parent array key with multidimensional arrays? for example I have this array:
array(
[0] => array(0=> sample, 1=>picture, 2=>frame, 3=>google)
[1] => array(0=> iphone, 1=>orange, 2=>love, 3=>msn)
[2] => array(0=> joe, 1=>geee, 2=>panda, 3=>yahoo)
)
现在我需要搜索例如google并获取父级数组键. 应该是0 ...任何想法?我为此使用了循环,但我认为如果我有700000行的数组,那将会很慢.
now I need to search for example google and get the parent array key.. which it should be 0...any ideas? I used for loop for this but I think it will be slow if I have arrays with 700000 rows..
推荐答案
如果您有一个具有700,000行的数组,则几乎可以肯定是做错了什么...我首先建议考虑使用其他数据存储:平面文件或某种类型的数据库.
If you have an array with 700,000 rows you are almost certainly doing something wrong... I would first recomend thinking about utilizing a different data store: flat file or some type of DB.
foreach($array as $key => $value) {
if(in_array('google', $value)) return $key
}
这篇关于用php获取多维数组中父数组键的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文