PHP array_merge () the array merge

array_merge (): incorporating one or more arrays. One or more of the merged array, array element attached behind the front of an array. 1. If there is a plurality of keys same string array, then the key name following values ​​overwrite the previous value. 2. If the same numeric keys, the value will not be overwritten, but is appended to, and the key name will be postponed. 3. If only passed in an array, then the array of index numbers will be re-indexed (index 0 will begin). 4. If you do not want to re-index, you can use the '+' sign, behind the same keys are ignored.

Consider the following simple example.

$arr1 = array('a'=>'a',0=>0,2=>2,'c'=>'c');
$arr2 = array('a'=>'b',2=>3,4=>4,'b'=>'b');
$arr = array_merge($arr1,$arr2);
print_r($arr);

Array
(
    [a] => b
    [0] => 0
    [1] => 2
    [c] => c
    [2] => 3
    [3] => 4
    [b] => b
)

$arr = array_merge($arr2);
print_r($arr);

Array
(
    [a] => b
    [0] => 3
    [1] => 4
    [b] => b
)

print_r($arr1+$arr2);

Array
(
    [a] => a
    [0] => 0
    [2] => 2
    [c] => c
    [4] => 4
    [b] => b
)

Guess you like

Origin blog.csdn.net/uvyoaa/article/details/83105196