我从mongodb获取数据 我从mongodb得到以下数组作为输出。 现在我尝试了许多PHP脚本来获取devicetype的计数,但没有得到预期的结果
Array
(
[0] => Array(
[_id] => 5774c1c17ffbe048da119681
[config] => Array(
[MOD001] => Array(
[devicetype] => modbus
[modbusManufacturer] => amit
[register_0] => Array
(
[value0] => UPS Power
[location0] => 2
)
[register_1] => Array
(
[value1] => Mains Power
[location1] => 2
)
)
[MOD002] => Array(
[devicetype] => modbus
[modbusManufacturer] => konsultera
[register_0] => Array
(
[value0] => Lobby Temp
[location0] => 22
)
[register_1] => Array
(
[value1] => Mains Power
[location1] => 2
)
)
[NBA001|NBR001|NBE001] => Array
(
[devicetype] => sensor
[zoneNo] => 2
)
[NBA002|NBR002|NBE002] => Array
(
[devicetype] => sensor
[zoneNo] => a
)
[RM001] => Array
(
[devicetype] => relay
[nodeId] => 001
)
[RM002] => Array
(
[devicetype] => relay
[nodeId] => 001
)
)
)
)
现在我需要像下面这样的devicetype modbus 2 继电器2 传感器2
答案 0 :(得分:0)
我还没有正确测试过这个,
function multi_array_search($array, $search)
{
foreach($array as $key => $value) {
if (is_array($value)) {
$sub = multi_array_search($value, $search);
if (count($sub)) {
return $array_occur_count;
}
}
}
}