I need to merge associative arrays and group by the name. Say I have such 3 arrays:
ARRAY1 \"/path/file.jpg\" => 2, \"/path/file2.bmp\" => 1,
one possible way
$rtn = array(); foreach ($array1 as $key=>$val) { $rtn[$key]+=$val; } foreach ($array2 as $key=>$val) { $rtn[$key]+=$val; } foreach ($array2 as $key=>$val) { $rtn[$key]+=$val; }
the above will assign the filename, SUM(val) as an associative array into $rtn
filename, SUM(val)
$rtn