What is the best way to sum the 'val' field with the same 'color' for each different color:
Array
(
[0] => Array
(
[color]=> "red"
[val]=> 4
)
[1] => Array
(
[color]=> "green"
[val]=> 3
)
[2] => Array
(
[color]=> "blue"
[val]=> 1
)
[3] => Array
(
[color]=> "green"
[val]=> 6
)
[4] => Array
(
[color]=> "blue"
[val]=> 2
)
)
Desired result : red: 4; green: 9; blue: 3.
Regards, Elio Fernandes
array_walkor callbacks, but there is something to be said about the readability of a simple loop. I would loop it. Also, 'best' is subjective. As far as performance is concerned, both methods are probably about the same.