How to merge several arrays into an array in PHP

Source: Internet
Author: User
How to merge several arrays into an array in PHP
Merging one-dimensional arrays
 
   

Merging two-dimensional arrays the array_merge_recursive () function in PHP can be implemented to merge elements of one or more arrays, and the values in an array are appended to the previous array. and returns an array as the result. When there are duplicate key names, the values are not overwritten, but the values of multiple identical key names are recursively grouped into an array.
Array_merge_recursive (Array1,array2,array3 ...)

Parameter description array1 required. The first array entered. Array2 required. The second array entered. Array3 is optional. Multiple input arrays that can be specified. For example:
 
  "Horse", "b" = "Dog");  $a 2=array ("c" = "Cow", "b" = "Cat"); Print_r (array_merge_recursive ($a 1, $a 2));? >



Note: the Array_merge () function can also be implemented, unlike the array_merge_recursive () function, if the key name is duplicated, the key is the value corresponding to the last key name (followed by overwriting the previous). If the array is a numeric index, the key name is re-indexed in a sequential manner.

  • 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.