The main difference is that if the same key name appears in two or more arrays, the key name is a string or a number, you need to be aware
1) When the key name is a number, array_merge () will not overwrite the original value, but the + merge array will return the first occurrence as the final result, and the values of the following array with the same key name "Discard" (not overwrite)
2) When the key name is a character, + still returns the first occurrence as the final result, and discards the value of the following array with the same key name, but Array_merge () overwrites the previous value of the same key name
It is important to note that the array key form ' number ' is equivalent to the number
Copy CodeThe code is as follows:
$a = Array (' A ', ' B ');
$b = Array (' C ', ' d ');
$c = $a + $b;
Var_dump ($a);
Var_dump (Array_merge ($a, $b));
$a = Array (0 = ' a ', 1 = ' B ');
$b = Array (0 = ' C ', 1 = ' B ');
$c = $a + $b;
Var_dump ($c);
Var_dump (Array_merge ($a, $b));
$a = Array (' A ', ' B ');
$b = Array (' 0 ' = ' c ', 1 = ' B ');
$c = $a + $b;
Var_dump ($c);
Var_dump (Array_merge ($a, $b));
$a = Array (0 = ' a ', 1 = ' B ');
$b = Array (' 0 ' = ' C ', ' 1 ' = ' B ');
$c = $a + $b;
Var_dump ($c);
Var_dump (Array_merge ($a, $b));
Results
Copy CodeThe code is as follows:
Array
0 = String ' a ' (length=1)
1 = string ' B ' (length=1)
2 = String ' C ' (length=1)
3 = String ' d ' (length=1)
Array
0 = String ' a ' (length=1)
1 = string ' B ' (length=1)
Array
0 = String ' a ' (length=1)
1 = string ' B ' (length=1)
2 = String ' C ' (length=1)
3 = String ' B ' (length=1)
Array
0 = String ' a ' (length=1)
1 = string ' B ' (length=1)
Array
0 = String ' a ' (length=1)
1 = string ' B ' (length=1)
2 = String ' C ' (length=1)
3 = String ' B ' (length=1)
Array
0 = String ' a ' (length=1)
1 = string ' B ' (length=1)
Array
0 = String ' a ' (length=1)
1 = string ' B ' (length=1)
2 = String ' C ' (length=1)
3 = String ' B ' (length=1)
http://www.bkjia.com/PHPjc/322163.html www.bkjia.com true http://www.bkjia.com/PHPjc/322163.html techarticle The main difference is that if the same key name is found in two or more arrays, the key name is broken into a string or a number, and you need to note that 1) when the key name is a number, array_merge () does not overwrite the original value ...