The difference between PHP array addition and array_merge

WBOY
Release: 2016-08-08 09:30:45
Original
1134 people have browsed it

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));

        }
Copy after login

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
)
Copy after login
<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
)
Copy after login

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.

Related labels:
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!