PHP array_merge_recursive ()

Source: Internet
Author: User

Definition and usage

The array_merge_recursive () function, like the Array_merge () function, merges the elements of one or more arrays and appends the values in an array to the previous array. and returns an array as the result.

However, unlike Array_merge (), 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. (see Example 1)

Grammar
1 array_merge_recursive (Array1,array2,array3 ...)
Parameters Describe
Array1 Necessary. The first array entered.
Array2 Necessary. The second array entered.
Array3 Optional. Multiple input arrays that can be specified.

Hints and Notes

Note: When you enter only one array to the array_merge_recursive () function, the result is the same as Array_merge ().

Example 1
<?php$a1 = Array ("A" = "Horse", "b" = "Dog"), $a 2 = array ("c" = "Cow", "b" = "Cat");p Rint_r (Array_merge_ Recursive ($a 1, $a 2));? >

Output:

1 Array ([a] = horse[b] = = Array ([0] = Dog [1] = Cat) [c] = Cow)

PHP array_merge_recursive ()

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.