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) );