Differences between array_merge and + in PHP

Source: Internet
Author: User
The difference between array_merge and + in PHP: array_merge () combines two or more arrays, and the values in an array are appended to the values of the previous array. Returns an array of results. If the input array contains the same string key name, the value after the key name overwrites the previous value. However, if the array contains a number key name, the subsequent values will not

The difference between array_merge and + in PHP: array_merge () combines two or more arrays, and the values in an array are appended to the values of the previous array. Returns an array of results. If the input array contains the same string key name, the value after the key name overwrites the previous value. However, if the array contains a number key name, the subsequent values will not

Differences between array_merge and + in PHP
  • Array_merge () combines two or more arrays. The values in an array are appended to the values of the previous array. Returns an array of results.
    If the input array contains the same string key name, the value after the key name overwrites the previous value. However, if the array contains a number key name, the subsequent values will not overwrite the original values, but will be appended to the back.
  • Merge arrays with "+:
    If the array contains the same key, the first value will be returned as the final result, and the values with the same key name in the subsequent array will be discarded (note: instead of overwriting, the value that appears first is retained ).

Original article address: the difference between array_merge and + in PHP. Thank you for sharing it with me.

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.