如果我有以下格式的 ID 号和数组,我如何找出 cat == 4 的所有其他项目中的计数(位置号)“红色”?我正在寻找的答案 #3 of 4. Array ( [0] => stdClass Object ( [id] => 1 [cat] => 1 [que] => Description here.)
[1] => stdClass Object
(
[id] => 2
[cat] => 1
[que] => Description here.
)
[2] => stdClass Object
(
[id] => 3
[cat] => 1
[que] => Description here.
)
....
[31] => stdClass Object
(
[id] => 32
[cat] => 4
[que] => Description here.
)
[32] => stdClass Object
(
[id] => 33
[cat] => 4
[que] => Description here.
)
[33] => stdClass Object
(
[id] => 34
[cat] => 4
[que] => Red.
)
[34] => stdClass Object
(
[id] => 35
[cat] => 4
[que] => Description here.
)
)
我需要拆分数组然后循环吗?丢失...
- - - - - 编辑 - - - - -
好吧,我解释得不好……
我的意思是:这个数组有很多对象。它们被分成组、类别。[cat] 是每个组的值。每个组中有多个项目。我希望得到的是每个组中的一些项目以及特定项目在该组中的位置,例如:12 个中的 4 个。