0
我有一個多維數組,並試圖通過一個鍵的值進行分組。如何使用鍵對多維ARRAY進行SUM和GROUP BY?
所以
Array (
[0] => Array (
[name] => Edward Foo
[desc_topic] => Array (
[0] => Apple
[1] => Banana
[2] => Orange
)
[qtd_posts] => Array (
[0] => 10
[1] => 20
[2] => 50
)
)
[1] => Array (
[name] => Michael Max
[desc_topic] => Array (
[0] => Apple
[1] => Banana
[2] => Orange
)
[qtd_posts] => Array (
[0] => 10
[1] => 10
[2] => 10
)
)
[2] => Array (
[name] => Edward Foo
[desc_topic] => Array (
[0] => Apple
[1] => Banana
[2] => Orange
)
[qtd_posts] => Array (
[0] => 5
[1] => 10
[2] => 30
)
)
[3] => Array (
[name] => Michael Max
[desc_topic] => Array (
[0] => Apple
[1] => Banana
[2] => Orange
)
[qtd_posts] => Array (
[0] => 8
[1] => 8
[2] => 20
)
)
,我真的需要:
Array (
[0] => Array (
[name] => Edward Foo
[desc_topic] => Array (
[0] => Apple
[1] => Banana
[2] => Orange
)
[qtd_posts] => Array (
[0] => 15
[1] => 30
[2] => 80
)
)
[1] => Array (
[name] => Michael Max
[desc_topic] => Array (
[0] => Apple
[1] => Banana
[2] => Orange
)
[qtd_posts] => Array (
[0] => 18
[1] => 18
[2] => 30
)
)
)
不知道我得到正確你的問題。 在你的例子中,你想按類型和總和級別進行分組嗎? 所以你想得到: standard = 9(1 + 1 + 7)and premier = 6(3 + 3)? – nico 2010-05-13 14:40:18
我想按名稱和總數「qtd_posts」itens分組。 可以嗎? – Oliveira 2010-05-13 14:54:14
你從數據庫中獲取這些值嗎?因爲在SQL中直接執行它會容易得多。否則,馬克的答案應該做些什麼。 – nico 2010-05-13 15:24:32