There is a little difference between array merging and array merging and array_merge array merging in PHP. Let me introduce to you the difference between array_merge and array merging.
+ :
The one that appears first will overwrite the one that appears later
array_merge:
What appears after
will overwrite what appears before. But if it is a numerical index, it is a superimposed effect.
The code is as follows
代码如下 |
复制代码 |
$array1 = Array(
0 => 111
);
$array2 = Array(
0 => 222,
1 => 3333
);
array_merge 后:
Array
(
[0] => 111
[1] => 222
[2] => 3333
)
+ 后:
Array
(
[0] => 111
[1] => 3333
)
情况二:
$array1 = Array(
0 => 111
);
$array2 = Array(
'h' => 222,
1 => 3333
);
array_merge 和 + 的结果是一样:
Array
(
[0] => 111
[h] => 222
[1] => 3333
)
|
|
Copy code
|
$array1 = Array(
0 => 111
);
| $array2 = Array(
0 => 222,
1 => 3333
);
array_merge after:
Array
(
[0] => 111
[1] => 222
[2] => 3333
)
+ After:
Array
(
[0] => 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] => 111
[h] => 222
[1] => 3333
)
The result is 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.
And + means adding two arrays will replace the same key value with the previous array. If the key value is different, it will have the same effect as array_merge.
http://www.bkjia.com/PHPjc/628658.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628658.htmlTechArticleThere is a little difference between the merging and adding of arrays and the merging of array_merge arrays in php. The following editor will give you some information Introduce the difference between array_merge and array addition and merge. + : The first one will be overwritten...