How to combine multiple numbers into an array and combine two-dimensional arrays with the same key

Source: Internet
Author: User
The array is like this. now we want to make the following results. thank you for your help.

The array is like this.


Now we want to achieve the following results:

Thank you!

Reply content:

The array is like this.


Now we want to achieve the following results:

Thank you!

Append an array
The array_merge_recursive () function is the same as the array_merge () function. two or more numbers can be combined to form a combined array. the difference between the two is that when a key in an input array already exists in the result array, the function will adopt different processing methods. array_merge () overwrites the existing key/value pairs and replaces them with the key/value pairs in the current input array. array_merge_recursive () merges the two values, form a new array and use the original key as the array name. Another form of array merging is recursively appending an array. The format is:
Array_merge_recursive (array array1, array array2 [..., Array arrayN])

The program example is as follows:

'$ Fruit1 = array ("apple" => "red", "banana" => "yellow ");
$ Fruit2 = array ("pear" => "yellow", "apple" => "green ");
$ Result = array_merge_recursive ($ fruit1, $ fruit2 );
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.