我得到的数组如下:
array(512) {
[0]=>
array(4) {
["@attributes"]=>
array(4) {
["id"]=>
string(4) "3048"
["net_id"]=>
string(4) "1344"
["city_id"]=>
string(3) "1021"
}
["shop"]=>
array(1) {
["@attributes"]=>
array(1) {
["status"]=>
string(6) "active"
}
}
}
[1]=>
array(2) {
["@attributes"]=>
array(3) {
["id"]=>
string(4) "2413"
["net_id"]=>
string(4) "1093"
["city_id"]=>
string(4) "1021"
}
["shop"]=>
array(1) {
["@attributes"]=>
array(1) {
["status"]=>
string(6) "active"
}
}
}
[2]=>
array(2) {
["@attributes"]=>
array(10) {
["id"]=>
string(4) "2413"
["net_id"]=>
string(4) "1093"
["city_id"]=>
string(4) "1131"
}
["shop"]=>
array(1) {
["@attributes"]=>
array(1) {
["status"]=>
string(6) "active"
}
}
}
}
我需要通过'city_id'=>找到数组索引'1021'代表
我找到它的功能。但它只搜索第一场比赛。 如何使用它进行多次匹配以获得具有$ key =>的数组索引? $值?
function array_find_deep($array, $search, $keys = array())
{
foreach($array as $key => $value) {
if (is_array($value)) {
$sub = array_find_deep($value, $search, array_merge($keys, array($key)));
if (count($sub)) {
return $sub;
}
} elseif ($value === $search) {
return array_merge($keys, array($key));
}
}
return array();
}