I'm not getting this right when trying to sum values of keys that are same within an associative array. I thought it's gonna be easy task, but it ain't the case so please...
I'm expecting following result:
1 -->(7)
2 -->(14)
Here's the array:
$array = array( 1=>4, 2=>8, 1=>3, 2=>6, );
Here's what i tried since:
$sum= array();
foreach ($array as $key => $value){ $sum[$key] += $value;} print_r($sum);
Anyway, there's no loop performed at all, since it's returning this result,
Array ( [1] => 3 [2] => 6 );
and an error,
Undefined offset: 1
I thought maybe there's a PHP function to handle it, but I'll be glad for any help.