How to merge arrays with same key and different value in PHP?

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-12-30T19:48:34Z Indexed on 2010/12/30 19:54 UTC
Read the original article Hit count: 173

Filed under:
|
|

Hi guys, I have arrays similarly to these:

0 => Array ( [0] => Finance / Shopping / Food, [1] => 47 )            
1 => Array ( [0] => Finance / Shopping / Food, [1] => 25 )                 
2 => Array ( [0] => Finance / Shopping / Electronic, [1] => 190 )  

I need to create one array with [0] as a key and [1] as value.
The tricky part is that if the [0] is same it add [1] to existing value.

So the result I want is:

array ([Finance / Shopping / Food]=> 72, [Finance / Shopping / Electronic] => 190);

thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays