In php, the combination of arrays and the combination of array_merge arrays is a little different. The following section will introduce the differences between the combination of array_merge and array.
+:
The first one will overwrite
Array_merge:
The later one will overwrite the previous one. However, if it is a digital index, it is a superposition effect.
| The Code is as follows: |
Copy code |
|
$ Array1 = Array (
0 => 111.
);
$ Array2 = Array (
0 => 222,
1 => 3333
);
After array_merge:
Array
(
[0] = & gt; 111
[1] => 222.
[2] => 3333.
)
+:
Array
(
[0] = & gt; 111
[1] => 3333.
)
Scenario 2:
$ Array1 = Array (
0 => 111.
);
$ Array2 = Array (
'H' => 222,
1 => 3333
);
The results of array_merge and + are the same:
Array
(
[0] = & gt; 111
[H] = & gt; 222
[1] => 3333.
) |
The results are obvious:
Array_merge is the addition of two arrays. If the key value is a number, it will be rearranged. If not, it will not be modified.
+ Is the addition of two arrays, which will replace the values of the same key value with the previous array. If the key value is different, it will have the same effect as array_merge.