The difference between PHP array merge and addition and array_merge_PHP tutorial

WBOY
Release: 2016-07-13 17:16:15
Original
1195 people have browsed it

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.

$array2 = Array( 0 => 222,
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
);

1 => 3333 );

array_merge after: ( [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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!