I want to achieve the following effect
$result = Array ( 100001=>array ( ' proc_id ' =>102, ' num ' =>2, ), 100002=>array ( ' proc_id ' =>100, ' num ' =>3, ') ; $new = Array ( //new array 100001=>array ( ' proc_id ' = >102, ' num ' =>2 ' ) ); $new 2 = Array ( //new array 2 100003=>array ( ' proc_id ' = 103, ' num ' =>2 ' ) );//The final result you want to achieve $result = Array ( 100001=>array ( ' proc_id ' =>102, ' num ' =>4, ), 100002=>array ( ' proc_id ' =>100, ' num ' =>3, ), 100003=>array ( ' proc_id ' =>103, ' num ' =>3, ) ); Don't know what to say?
Reply to discussion (solution)
Array_merge
$ar =array_combine (Array_merge (Array_keys ($new), Array_keys ($new 2)), Array_merge ($new, $new 2)), foreach ($ar as $k = > $v) { if (! $result [$k]) { $result [$k] = $v;} else{ $result [$k] [' num '] + = $v [' num '];}} Print_r ($result);
1 floor of the method if the key value of the string is OK, but the number of key values do not work, the landlord can use my following method
$arr = $result + $new + $new 2;
Print_r ($arr);