The two differences are:
1. When the array key name is a numeric key name, the two arrays to be merged have the same name as the number key, using Array_merge () will not overwrite the original value, while using "+" to merge the array will return the first occurrence of the value as the final result, and the following array with the same key name of those values "discard" (note: Instead of overwriting, it retains the first value that appears). Example:
$array 1 = Array (1=> ' 0′);
$array 2 = Array (1=> "data");
$result 1 = $array 2 + $array 1;/* result is the value of $array2 */
Print_r ($result);
$result = $array 1 + $array 2;/* The result is a value of $array1 */
Print_r ($result);
$result 3 = Array_merge ($array 2, $array 1);/* The result is a value of $array2 and $array1, and the key name is reassigned */
Print_r ($result 3);
$result 4 = Array_merge ($array 1, $array 2);/* The result is a value of $array1 and $array2, and the key name is reassigned */
Print_r ($result 4);
The output is:
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 the key name, but Array_merge () overrides the previous value of the same key name.
Example:
$array 1 = Array (' ASD ' = ' 0′ ');
$array 2 = Array (' ASD ' = ' data ');
$result 1 = $array 2 + $array 1;/* result is the value of $array2 */
Print_r ($result);
$result = $array 1 + $array 2;/* The result is a value of $array1 */
Print_r ($result);
$result 3 = Array_merge ($array 2, $array 1);/* result is $array1*/
Print_r ($result 3);
$result 4 = Array_merge ($array 1, $array 2);/* result is $array2*/
Print_r ($result 4);
The output is:
Array ([ASD] = data)
Array ([ASD] = 0)
Array ([ASD] = 0)
Array ([ASD] = data)