This article mainly introduced the PHP merge array + number and array_merge difference, the PHP array fusion generally has two kinds of practices, one is to use the plus sign directly to add, the other is to use the Array_merge function to add, the two are somewhat different, needs the friend to be possible to refer to under
There are generally two ways to use PHP for array fusion, one is to add directly with the plus sign, and the other is to add by using the Array_merge function, which is a bit different:
1. The natural index in the array will not be reset
2. In the addition method, the values in the added array are not overwritten
The natural index in the 3.merge function will be reset
4.merge function, does not matter by the merge and the merge relationship, the more the array parameter, its value, will overwrite the previous array parameter same key value
Example:
Array 1:
?
| 1 2 3 4 5 6 7 8 9 10 11 12-13 |
$arr 1 = Array (=> ' valueof10 ', => ' valueof11 ', ' key1 ' => ' dataofkey1 ', ' key2 ' => ', ' dataofkey2 ', ' array ' = > Array (' Key1 ' => 1, ' Key2 ' => ' abc ', ' Key3 ' => array (1, 2, ' name ' => ' Peter '),); |
Array 2:
?
| 1 2 3 4 5 6 7 8 9 10 11 12-13 |
$arr 2 = Array (=> ' newvalueof10 ', => ' newvalueof11 ', ' key1 ' => ' newdataofkey1 ', ' Key3 ' => ') Newdataofkey3 ', ' array ' => array (' Key1 ' => 2, ' Key2 ' => ' defg ', ' Key3 ' => array (1, 2, ' name ' => ' Jonathan ', ' gender ' = > ' male '),); |
Results comparison:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The |
|