Array_merge in the reference manual are as follows:
array_merge () combines two or more arrays of cells, and the values in one array are appended to the previous array. Returns an array as the result.
If you enter an array that has the same string key name, the value that follows the key name overrides the previous value. However, if the array contains a numeric key name, the subsequent value will not overwrite the original value, but append to the back.
The difference between the two
is:
1. When the array key name is a numeric key name, when there is a number key in the two array to be merged with the same name, using Array_merge () does not overwrite the original value, and using the "+" merge array will return the first occurrence as the final result, while the following array has the same key name values " Discard the "Off" (note: not overwrite but retain the first occurrence of the value). Example:
Copy Code code as follows:
$array 1 = array (1=> ' 0 ');
$array 2 = Array (1=> "data");
$result 1 = $array 2 + $array 1;/* result is $array2 value * *
Print_r ($result);
$result = $array 1 + $array 2;/* Result $array1 Value * *
Print_r ($result);
$result 3 = Array_merge ($array 2, $array 1),/* results are $array2 and $array1 values, the key name is reassigned * *
Print_r ($result 3);
$result 4 = Array_merge ($array 1, $array 2),/* results are $array1 and $array2 values, the key name is reassigned * *
Print_r ($result 4);
output results are:
Copy Code code as follows:
Array
(
[1] => data
)
Array
(
[1] => 0
)
Array
(
[0] => data
[1] => 0
)
Array
(
[0] => 0
[1] => data
)
2. When the same array key name is a character, the "+" operator is the same as when the key is a number, but Array_merge () overrides the previous value of the same key name.
Example:
Copy Code code as follows:
$array 1 = Array (' ASD ' => ' 0 ');
$array 2 = Array (' ASD ' => "data");
$result 1 = $array 2 + $array 1;/* result is $array2 value * *
Print_r ($result);
$result = $array 1 + $array 2;/* Result $array1 Value * *
Print_r ($result);
$result 3 = Array_merge ($array 2, $array 1);/* The result is $array1*/
Print_r ($result 3);
$result 4 = Array_merge ($array 1, $array 2);/* The result is $array2*/
Print_r ($result 4);
output results are:
Copy Code code as follows:
Array
(
[ASD] => data
)
Array
(
[ASD] => 0
)
Array
(
[ASD] => 0
)
Array
(
[ASD] => data
)