php mathematical addition of numerical values in 2 associative arrays -


probably simple 1 :

i have 2 arrays

$array1 = array(   'foo' => 5,   'bar' => 10,   'baz' => 6 );  $array2 = array(   'x' => 100,   'y' => 200,   'baz' => 30 ); 

i wish third array combining both above, should :

$result_array = array(   'foo' => 5,   'bar' => 10,   'baz' => 36,   'x' => 100,   'y' => 200, ); 

is there built in 'array - way' this, or have write own function ? thanks

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

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -