Possible Duplicate:
PHP Array_Sum on multi dimensional array
I am having a two dimesional array as follows.
array(
(int) 0 => array(
'Chrome' => '10',
'Firefox' => '3',
'Internet Explorer' => '1',
'Safari' => '1',
'Mobile' => (int) 0,
'Others' => (int) 0
),
(int) 1 => array(
'Chrome' => '5',
'Firefox' => '2',
'Safari' => '2',
'Internet Explorer' => '1',
'Opera' => '1',
'Mobile' => (int) 0,
'Others' => (int) 0
)
)
I want to add values for same keys and get it into single array as follows.
array(
'Chrome' => '15',
'Firefox' => '5',
'Internet Explorer' => '2',
'Safari' => '3',
'Opera' => '1',
'Mobile' => '0'
'Others' => '0'
)
Please give me solution for this.
Iterate over the sub-arrays and take over key and value pairs. In case they exist, add the value (integer arithmetical sum operation) to the existing value.
When you are done with iterating the sub-arrays, the result is ready.