how to add values of two arrays with common index in php? -


this question has answer here:

consider following arrays:

array 1 contents:

index1    value2         5 b         6 c         2 

and array 2 contents:

index2   value2         4 b         2 

i need array 3 should sum of above 2 arrays. like:

index     value           9 b           8 c           2 

this function need:

function array_merge_with_sum_values(array $array1, array $array2){         $finalarray = array_merge($array1, $array2);         $keys = array_keys($finalarray);         foreach($keys $key){             if(isset($array1[$key]) && isset($array2[$key])){                 $finalarray[$key] = $array1[$key] + $array2[$key];             }         }         return $finalarray;     } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -