The main difference is that if the same key name appears in two or more arrays, the key name can be divided into strings or numbers.
1) when the key name is a number, array_merge () will not overwrite the original value, but + merges the array and returns the first value as the final result, the values of the following arrays with the same key names are discarded (not overwritten)
2) When the key name is a character, + still returns the first value as the final result, and discards the values with the same key name in the subsequent array, but array_merge () at this time, the values with the same key names will be overwritten.
Note that the array key form 'number' is equivalent to a number.
Copy codeThe Code is as follows:
$ A = array ('A', 'B ');
$ B = array ('C', 'D ');
$ C = $ a + $ B;
Var_dump ($ );
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 ));
Result
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)