感谢Jonathan Kuhn,我已更新此主题以反映您的建议。
我有以下数组,它只是名为$ array
Array
(
[0] => Array
(
[id] => 10213
[branch] => 1
[parent] => 10183
[age] => 53
)
[1] => Array
(
[id] => 10230
[branch] => 1
[parent] => 10213
[age] => 22
)
[2] => Array
(
[id] => 10232
[branch] => 1
[parent] => 10213
[age] => 17
)
[3] => Array
(
[id] => 10234
[branch] => 1
[parent] => 10232
[age] => 6
)
[4] => Array
(
[id] => 10223
[branch] => 2
[parent] => 10183
[age] => 31
)
[5] => Array
(
[id] => 10231
[branch] => 3
[parent] => 10183
[age] => 19
)
[6] => Array
(
[id] => 10260
[branch] => 3
[parent] => 10231
[age] => 22
)
[7] => Array
(
[id] => 10261
[branch] => 3
[parent] => 10231
[age] => 16
)
)
[branch]表示家谱顶部的人的原始子项。
因此,例如,我想循环并能够搜索$ array,以查找同时位于[branch] =>的“21”年龄的所有人的总数。等等
感谢任何帮助,谢谢!
答案 0 :(得分:1)
您可以使用array_filter()
,应用您的条件并获取结果数组的大小:
$foo = array_filter($array, function($a) {
return $a["age"] > 21 && $a["branch"] == 1;
});
echo(count($foo));