Copy CodeThe code is as follows:
function Array_add ($a, $b) {
Gets the intersection of two arrays based on the key name
$arr =array_intersect_key ($a, $b);
Iterates through the second array if the key name does not exist with the first array, adding the array element to the first array
foreach ($b as $key = = $value) {
if (!array_key_exists ($key, $a)) {
$a [$key]= $value;
}
}
Computes the and of the same array element with the same key name, and replaces the element value corresponding to the same key name in the original array
foreach ($arr as $key = = $value) {
$a [$key]= $a [$key]+ $b [$key];
}
Returns the added array
return $a;
}
$a = Array (' 0 ' = ' 2 ', ' 1 ' = ' 4 ', ' 3 ' = ' 8 ', ' a ' = ' 100 ');
$b = Array (' 0 ' = ' 5 ', ' 2 ' = ' 4 ', ' b ' = ' + ', ' a ' = ' 22 ');
$arr =array_add ($a, $b);
Print_r ($arr);
?>
http://www.bkjia.com/PHPjc/323646.html www.bkjia.com true http://www.bkjia.com/PHPjc/323646.html techarticle Copy the code as follows: Php function Array_add ($a, $b) {//Gets the intersection of two arrays based on the key name $arr =array_intersect_key ($a, $b);//traverse the second array if the key name does not exist ...