php - is it possible to array push value into existing array value with sum? -


is possible array push value existing array value sum?

$nvarr = array("1"=> 35, "2"=> 1, "3"=> 2, "8"=> 56, "9"=> 78); 

i have add 1 more array value existing array

$nvarr1 = array("1"=> 35, "2"=> 1); 

and want following out put

$nvarr = array("1"=> 70, "2"=> 2, "3"=> 2, "8"=> 56, "9"=> 78); 

you can foreach

foreach($nvarr1 $key => $val){   (array_key_exists($key, $invarr))?     $invarr[$key] += $nvarr1[$key]     : $invarr[$key] = $nvarr1[$key] } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -