for +, when the key is at the same time, regardless of whether the key is a character or an array, it discards the subsequent result ;
Array_merge, when key is at the same time, key is a character, then the previous one is overwritten, the key is a number, and no overwrite occurs, and the array index is re-established.
<?php $arr 1 = array ( ' a ' => ' PHP '); $arr 2 = array ( ' a ' => ' JAVA '); //if the key name is a character and the key name is the same, the value of the array element after Array_merge () overrides the previous array element value Print_r (Array_merge ( $arr 1, $arr 2)); //array ([a] = JAVA) //if the key name is a character and the key name is the same, The addition of the array will result in the first occurrence of the value Print_r ( $arr 1+ $arr 2); //array ([a] = PHP) ?>
If the key name is a number, the difference:
<?php $arr 1 = array (" C ", "PHP"); $arr 2 = array ( "JAVA", "PHP"); //if the key name is a number, array_merge () will not overwrite Print_r (Array_merge ( $arr 1, $arr 2)); //array ([0] = C [1] + php [2] = + JAVA [3] = PHP) // If the key name is an array, the sum of the arrays will be the first occurrence of the value as a result, the following key name will be discarded Print_r ( $arr 1+$ ARR2); //array ([0] = C [1] = PHP) ?>
" how to get the most efficient set of two array values with the same character key name and different values", array_merge_recursive-recursively merges one or more arrays, if the input array has the same string key name, The values are merged into an array .
<?php
$arr 1 = array ( "a" => "php", "C"); $arr 2 = array ( "a" => "Java", Span class= "hljs-string" > "C", "Ruby");p Rint_r (Array_merge_recursive ( $arr 1, $arr 2)); ?> results are as follows: array ([a] = Array ([0] + php [1] + java) [0 ] = c [1] + c [2] + Ruby) /span>
Php-array_merge and + Difference