array_key_exists不工作 [英] array_key_exists is not working
本文介绍了array_key_exists不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
array_key_exists不工作对于大型多维数组。对于前
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('测试',$ ARR)返回假,但它与一些简单数组的作品。
array_key_exists('test',$arr) returns 'false' but it works with some simple arrays.
推荐答案
array_key_exists不工作递归(如<一个href=\"http://stackoverflow.com/questions/2948948/array-key-exists-is-not-working#comment3005438_2948948\">Matti Virkkunen 已经指出的那样)。看看PHP手册,有以下件code的你可以用它来执行递归搜索:
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:
<?php
function array_key_exists_r($needle, $haystack)
{
$result = array_key_exists($needle, $haystack);
if ($result) return $result;
foreach ($haystack as $v) {
if (is_array($v)) {
$result = array_key_exists_r($needle, $v);
}
if ($result) return $result;
}
return $result;
}
这篇关于array_key_exists不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文