How to combine multiple arrays into an array, merging two-dimensional arrays with the same key

Source: Internet
Author: User

The array is like this


Now want to do the following effect

Great gods, help me.

Reply content:

The array is like this


Now want to do the following effect

Great gods, help me.

Append array
The array_merge_recursive () function is the same as Array_merge () and can combine two or more numbers together to form an array of unions. The difference between the two is that when a key in an input array is already in the result array, the function takes a different approach. Array_merge () overrides the previously existing key/value pair, replacing it with the key/value pair in the current input array, and array_merge_recursive () merges two values together to form a new array with the original key as the array name. There is also the form of an array merge, which is a recursive append array. The form is:
Array_merge_recursive (array Array1,array array2[...,array Arrayn])

The program examples are as follows:

' $fruit 1 = array ("Apple" = "red", "banana" = "yellow");
$fruit 2 = Array ("pear" + "yellow", "apple" = "green");
$result = array_merge_recursive ($fruit 1, $fruit 2);
Print_r ($result);

Output
Array ([Apple] = Array ([0] = red [1] = = green) [Banana] = yellow [pear] = yellow) '

Array_merge

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.