Accumulate 2D Array by Index
Posted
by Tegan Snyder
on Stack Overflow
See other posts from Stack Overflow
or by Tegan Snyder
Published on 2010-03-26T19:07:14Z
Indexed on
2010/03/26
19:13 UTC
Read the original article
Hit count: 360
I have an array that looks like this:
Array
(
[0] => Array
(
[amount] => 60.00
[store_id] => 1
)
[1] => Array
(
[amount] => 40.00
[store_id] => 1
)
[2] => Array
(
[amount] => 10.00
[store_id] => 2
)
)
What would be a good method to reduce the array to a similar array that totals the 'amount' related to a store_id.
For Instance I'd like to get this:
Array
(
[0] => Array
(
[amount] => 100.00
[store_id] => 1
)
[2] => Array
(
[amount] => 10.00
[store_id] => 2
)
)
© Stack Overflow or respective owner