的價值我有一個數組,看起來像這樣PHP基於特定元素
Array (
[0] => Array
(
[id] => 123
[count] => 1
)
[1] => Array
(
[id] => 123
[count] => 3
)
[2] => Array
(
[id] => 513
[count] => 0
)
[3] => Array
(
[id] => 561
[count] => 1
)
[4] => Array
(
[id] => 613
[count] => 7
)
)
我想要做的就是創建一個新的數組什麼組合陣列,即總計其中ID值相同的次數。因此,例如,新陣列看起來像這樣:
Array (
[0] => Array
(
[id] => 123
[count] => 4
)
[1] => Array
(
[id] => 513
[count] => 0
)
[2] => Array
(
[id] => 561
[count] => 1
)
[3] => Array
(
[id] => 613
[count] => 7
)
)
有人會知道一個很好的方法來做到這一點嗎?
謝謝!
只是迭代並創建一個新的數組,如果id與先前的id相同(保存)並添加計數,但我覺得必須有更好的方法 – dzm 2012-07-24 20:46:48