PHP number combinations with Plus and array_merge () differences

Source: Internet
Author: User

First look at the array elements:

<?php$a = Array (' R ' =>1,2,3,4); Var_dump (' A ', $a); $b = Array (' R ' =>5,6,7,8); Var_dump (' B ', $b); $c = Array (' r ' = >5,6,7,8,9) var_dump (' C ', $c) var_dump (' a+b ', $a + $b) var_dump (' a+c ', $a + $c) var_dump (' Amb ', array_merge ($a, $b)) ; Var_dump (' AMC ', Array_merge ($a, $c));


Second look at the output:

string  ' A '   (length=1) array   ' R '  => int 1  0 =>  int 2  1 => int 3  2 => int 4string  ' B '   (length=1) array   ' R '  => int 5  0 => int 6   1 => int 7  2 => int 8string  ' C '   (length=1) array    ' R '  => int 5  0 => int 6  1 =>  int 7  2 => int 8  3 => int 9string  ' A +b '   (length=3) array   ' R '  => int 1  0 => int 2   1 => int 3  2 => int 4string  ' a+c '   (length =3) array   ' R '  => int 1  0 => int 2  1 = > int 3  2 => int 4  3 => int 9string  ' Amb '   (length=3) array   ' R '  => int 5  0 => int 2  1 = > int 3  2 => int 4  3 => int 6   4 => int 7  5 => int 8string  ' AMC '   (length=3) array   ' R '  => int 5  0 => int 2  1 = > int 3  2 => int 4  3 => int 6   4 => int 7  5 => int 8  6 => int  9


Conclusion: Combine the array with plus sign: Consider both the key-value pairs of the numeric indexes, the key-value pairs of the string indexes, and the values of the key-names in the front arrays.

Merge the array with Array_merge (): Only consider the key-value pairs of the string index, overwrite the value of the previous array with the same key name, and the value of the numeric index is not overwritten while preserving

Also: Array_merge () will rearrange the number index of two arrays, "+" does not


PHP number combinations with Plus and array_merge () differences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.