php - Two different kinds of arrays -


i have 2 different arrays below:

array ( [1] => 2 [2] => 3 [6] => 1 ) ; // array1 has 3 keys , 3 value 1=>2, 2=>3, 6=>1  array ( [1] => 2 [6] =>2 ) ;           // array2 has 2 keys , 2 value 1=>2, 6=>1  

i want array1 , array2 same key can sum both value:

ex: array1 "[1]=>2" , array2 "[1]=>2" want out put [1]=>4; [6]=>3 

$result = array(); foreach ($array1 $key => $value) {     if (isset($array2[$key])) {         $result[$key] = $value + $array2[$key];     } } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -