array_key_exists 不起作用
array_key_exists 不适用于大型多维数组。对于前
$arr = array(
'1' => 10,
'2' => array(
'21' => 21,
'22' => 22,
'23' => array(
'test' => 100,
'231' => 231
),
),
'3' => 30,
'4' => 40
);
array_key_exists('test',$arr) 返回 'false' 但它适用于一些简单的数组。
array_key_exists is not working for large multidimensional array. For ex
$arr = array(
'1' => 10,
'2' => array(
'21' => 21,
'22' => 22,
'23' => array(
'test' => 100,
'231' => 231
),
),
'3' => 30,
'4' => 40
);
array_key_exists('test',$arr) returns 'false' but it works with some simple arrays.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
array_key_exists 不能递归工作(正如 Matti Virkkunen 已经指出的那样)。看一下PHP手册,有以下内容 您可以使用一段代码来执行递归搜索:
array_key_exists does NOT work recursive (as Matti Virkkunen already pointed out). Have a look at the PHP manual, there is the following piece of code you can use to perform a recursive search:
array_key_exists 不适用于多维数组。如果你想这样做,你必须编写自己的函数,如下所示:
如果找不到密钥,则返回 false ,或者返回包含该数组中密钥“位置”的字符串(例如
2:23:test
) 如果找到的话。array_key_exists doesn't work on multidimensionaml arrays. if you want to do so, you have to write your own function like this:
this returns
false
if the key isn't found or a string containing the "location" of the key in that array (like2:23:test
) if it's found.这需要 PHP 5.3 或更高版本。
This requires PHP 5.3 or later.
这是另一个,适用于任何维度数组
Here is another one, works on any dimension array