我有一個數組,我從數據庫查詢響應中獲取。從數組中計數相同的類別和在新的數組中存儲它的計數和類別名稱
現在我想統計相同的類別並在option_name數組中打印。 我已經嘗試了不同的陣列功能,但想獲得慾望輸出。
我有一個想法,採取新的數組,並推它與foreach循環,但沒有太多的想法,我怎麼能實現使用代碼。請幫我解決它。
Array
(
[0] => Array
(
[CNC] => Array
(
[id] => 5
[category_id] => 68
)
[GVO] => Array
(
[option_name] => Actors
)
)
[1] => Array
(
[CNC] => Array
(
[id] => 11
[category_id] => 72
)
[GVO] => Array
(
[option_name] => Cricketers
)
)
[2] => Array
(
[CNC] => Array
(
[id] => 3
[category_id] => 72
)
[GVO] => Array
(
[option_name] => Cricketers
)
)
[3] => Array
(
[CNC] => Array
(
[id] => 4
[category_id] => 74
)
[GVO] => Array
(
[option_name] => Musician
)
)
[4] => Array
(
[CNC] => Array
(
[id] => 7
[category_id] => 76
)
[GVO] => Array
(
[option_name] => Directors
)
)
[5] => Array
(
[CNC] => Array
(
[id] => 6
[category_id] => 76
)
[GVO] => Array
(
[option_name] => Directors
)
)
)
慾望輸出:
Array
(
[Actors] => 1
[Cricketers] => 2
[Musician] => 1
[Directors] => 2
)
提前感謝!
遍歷該數組,並檢查它是否與存儲在新的數組。 –
我的腳本不幫你嗎? –
是的,它工作得很好。 @FrayneKonok – RJParikh