Home  >  Article  >  Backend Development  >  The difference between PHP array addition and array_merge

The difference between PHP array addition and array_merge

WBOY
WBOYOriginal
2016-08-08 09:30:451175browse

The powerful functions of PHP array processing lead to various data processing functions.

Among them, array addition and array_merge caused the author to step into a small pit.

1
        public function action_test54(){
                $a = array(
                        '0'=>1567,
                        '1'=>1568,
                        '2'=>1569,
                        '3'=>1570,
                );
                $b = array(
                        '1'=>1571,
                        '2'=>1572,
                        '3'=>1573,
                        '4'=>1574
                );
                d($a + $b);
                dd(array_merge($a,$b));

        }

Demo2 output:

<small>array</small>(5) (
    0 => <small>integer</small> 1567
    1 => <small>integer</small> 1568
    2 => <small>integer</small> 1569
    3 => <small>integer</small> 1570
    4 => <small>integer</small> 1574
)
<small>array</small>(8) (
    0 => <small>integer</small> 1567
    1 => <small>integer</small> 1568
    2 => <small>integer</small> 1569
    3 => <small>integer</small> 1570
    4 => <small>integer</small> 1571
    5 => <small>integer</small> 1572
    6 => <small>integer</small> 1573
    7 => <small>integer</small> 1574
)

Conclusion:

$a + $b incremental coverage


array_merger($a,$b) $b replaces $a first

The above has introduced the difference between PHP array addition and array_merge, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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