The difference between Array_merge and Array+array in PHP

Source: Internet
Author: User
This article describes the differences between Array_merge for array merging and Array+array for merging. If you need a friend, refer to it.

Note: in PHP, Array_merge discards the original number key, while preserving the string form of key, and then forming a new array, regardless of whether the key name is the same, do not merge, unless the key name and value are the same, and the string form of the key is merged. But the Array+array is different, it will only first put the previous array of data into the newly generated array, and then see whether the second array is more than the first array, more than the number of added, it is only a few numbers, but this situation it will be added. This is the difference between the two.

Take a look at the following example:

 
      ' Aass ', ' e ' = ' adsdfd ', ' asd ' = ' asdsdd ', ' ddfg ' = ' dssdf '); $b = Array (' d ' = = ' adddd ', ' adsdfd ', ' asdfsddddd ', ' d ' = ' aass '); $d = $a + $b; $e = Array_merge ($a, $b); Var_dump ($d); Var_dump ($e);? >

Output Result:

Array ' d ' = = String ' Aass ' (length=4) ' e ' = = String ' ADSDFD ' (length=6) ' asd ' = String ' ASDSDD ' (length=6) ' DDFG ' = = String ' dssdf ' (length=5) 0 = String ' adsdfd ' (length=6) 1 = String ' asdfsddddd ' (length=10) array ' d ' =&gt ; String ' Aass ' (length=4) ' e ' = + string ' adsdfd ' (length=6) ' asd ' = String ' ASDSDD ' (length=6) ' ddfg ' = = String ' Dssdf ' (length=5) 0 = String ' adsdfd ' (length=6) 1 = String ' asdfsddddd ' (length=10)
  • Related Article

    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.