In PHP, you can use the Array_merge function and two arrays to add Array+array way to do the array merge, but the effect is not the same, the following is to introduce the specific use of the difference between the two.
The difference is as follows:
Array_merge () does not overwrite the original value when it is labeled as a value, but the Array+array merge array returns the first occurrence as the final result, and the values of the following array with the same key name are "discarded" (not overwritten).
When labeled as a character, Array+array still returns the first occurrence as the final result, and discards the values of the following array with the same key name, but Array_merge () overwrites the previous value of the same key name.
Example 1:
Code:
$arr 1 = [' PHP ', ' Apache '];
$arr 2 = [' PHP ', ' MySQl ', ' HTML ', ' CSS '];
$MERGEARR = Array_merge ($arr 1, $arr 2);
$PLUSARR = $arr 1 + $arr 2;
Var_dump ($MERGEARR);
Var_dump ($PLUSARR);
Results
$MERGEARR:
Array (size=6)
0 = String ' PHP ' (length=3)
1 = String ' Apache ' (length=5)
2 = String ' PHP ' (length=3)
3 = String ' MySQl ' (length=5)
4 = String ' HTML ' (length=4)
5 = String ' CSS ' (length=3)
$plusArr
Array (size=4)
0 = String ' PHP ' (length=3)
1 = String ' Apache ' (length=5)
2 = String ' HTML ' (length=4)
3 = String ' CSS ' (length=3
Example 2:
Code:
$arr 1 = [' PHP ', ' a ' = ' MySQl '];
$arr 2 = [' PHP ', ' MySQl ', ' a ' = ' + ' HTML ', ' CSS '];
$MERGEARR = Array_merge ($arr 1, $arr 2);
$PLUSARR = $arr 1 + $arr 2;
Var_dump ($MERGEARR);
Var_dump ($PLUSARR);
Results
$MERGEARR:
Array (size=5)
0 = String ' PHP ' (length=3)
' A ' = = String ' HTML ' (length=4)
1 = String ' PHP ' (length=3)
2 = String ' MySQl ' (length=5)
3 = String ' CSS ' (length=3)
$plusArr
Array (size=4)
0 = String ' PHP ' (length=3)
' A ' = = String ' MySQl ' (length=5)
1 = String ' MySQl ' (length=5)
2 = String ' CSS ' (length=3)
Example 3:
Code:
$arr 1 = [' PHP ', ' a ' = = ' MySQl ', ' 6 ' = ' CSS '];
$arr 2 = [' PHP ', ' MySQl ', ' a ' = ' + ' HTML ', ' CSS '];
$MERGEARR = Array_merge ($arr 1, $arr 2);
$PLUSARR = $arr 1 + $arr 2;
Var_dump ($MERGEARR);
Var_dump ($PLUSARR);
Results:
$mergeArr
Array (size=6)
0 = String ' PHP ' (length=3)
' A ' = = String ' HTML ' (length=4)
1 = String ' CSS ' (length=3)
2 = String ' PHP ' (length=3)
3 = String ' MySQl ' (length=5)
4 = String ' CSS ' (length=3)
$plusArr
Array (size=5)
0 = String ' PHP ' (length=3)
' A ' = = String ' MySQl ' (length=5)
6 = String ' CSS ' (length=3)
1 = String ' MySQl ' (length=5)
2 = String ' CSS ' (length=3)
The difference between Array_merge function and Array+array in PHP