Php merge array ~ According to the value of a column

Source: Internet
Author: User
For example, two Arrays: {code ...} I want to merge the AB array into an array and combine it according to the same [time] to achieve the following effect: {code ...} similar to database & quot; fulljoin & quot;, is there a way to implement this? Two arrays are as follows:

A=[[0] =>[[time] => 2015-11-01,          [draw] => 900],   [1] =>[[time] => 2015-11-02,          [draw] => 1512],   [2] =>[[time] => 2015-11-05,          [draw] => 1600]];          B=[[0] =>[[time] => 2015-11-01,          [data] => 90],   [1] =>[[time] => 2015-11-03,          [data] => 152],   [2] =>[[time] => 2015-11-05,          [data] => 100]];          

I want to merge the AB array into an array and combine them according to the same [time] to achieve the following effect:

C=[[0] =>[[time] => 2015-11-01,          [draw] => 900,  [data] => 90],   [1] =>[[time] => 2015-11-02,          [draw] => 1512],   [2] =>[[time] => 2015-11-03,                          [data] => 152],   [3] =>[[time] => 2015-11-05,          [draw] => 1300, [data] => 100]];          

Similar to the database's "full join", is there a way to implement this?

Reply content:

Two arrays are as follows:

A=[[0] =>[[time] => 2015-11-01,          [draw] => 900],   [1] =>[[time] => 2015-11-02,          [draw] => 1512],   [2] =>[[time] => 2015-11-05,          [draw] => 1600]];          B=[[0] =>[[time] => 2015-11-01,          [data] => 90],   [1] =>[[time] => 2015-11-03,          [data] => 152],   [2] =>[[time] => 2015-11-05,          [data] => 100]];          

I want to merge the AB array into an array and combine them according to the same [time] to achieve the following effect:

C=[[0] =>[[time] => 2015-11-01,          [draw] => 900,  [data] => 90],   [1] =>[[time] => 2015-11-02,          [draw] => 1512],   [2] =>[[time] => 2015-11-03,                          [data] => 152],   [3] =>[[time] => 2015-11-05,          [draw] => 1300, [data] => 100]];          

Similar to the database's "full join", is there a way to implement this?

function setKeyByTime($arr) {    $res = array();    foreach($arr as $item) {        $res[$item['time']] = $item;    }    return $res;}$C = array_merge_recursive( setKeyByTime($A), setKeyByTime($B) );

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.