3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1= [ [ "month1" => "January", "2020cs" => 84, "2020as" => 500, "2019cs" => 17, "2019as" => 500, ], [ "month1" => "February", "2020cs" => 54, "2020as" => 200, "2019cs" => 12, "2019as" => 1000, ], [ "month1" => "April", "2020cs" => 4, "2020as" => 100, "2019cs" => 12, "2019as" => 1400, ], [ "month1" => "November", "2020cs" => 0, "2020as" => 0, "2019cs" => 7, "2019as" => 200, ], ]; $array2= [ [ "month1" => "January", "2020cr" => 13, "2020ar" => 300, "2019cr" => 0, "2019ar" => 0, ], [ "month1" => "March", "2020cr" => 1, "2020ar" => 100, "2019cr" => 0, "2019ar" => 0, ], [ "month1" => "November", "2020cr" => 0, "2020ar" => 0, "2019cr" => 1, "2019ar" => 800, ], [ "month1" => "December", "2020cr" => 0, "2020ar" => 0, "2019cr" => 2, "2019ar" => 500, ], ]; // top-level array from indexed to associative (name of month) $array1 = rekey($array1); $array2 = rekey($array2); function rekey(array $arr = []): array { foreach ($arr as $key => $record) { $arr[$record['month1']] = $arr[$key]; // indexed to name of month unset($arr[$key]); } return $arr; } // run the merge $result = array_merge_recursive($array1, $array2); // clean up double entries key 'month1' foreach($result as $key => &$value) { if(is_array($value['month1'])) $value['month1'] = $value['month1'][0]; } // sort result set $months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; foreach($result as $key0 => $value0) { foreach($months as $key1 => $value1) { if($key0 === $value1) { $result[$key1] = $result[$key0]; // set index based on month 0-11 unset($result[$key0]); } } } ksort($result); print_r(array_values($result));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [month1] => January [2020cs] => 84 [2020as] => 500 [2019cs] => 17 [2019as] => 500 [2020cr] => 13 [2020ar] => 300 [2019cr] => 0 [2019ar] => 0 ) [1] => Array ( [month1] => February [2020cs] => 54 [2020as] => 200 [2019cs] => 12 [2019as] => 1000 ) [2] => Array ( [month1] => March [2020cr] => 1 [2020ar] => 100 [2019cr] => 0 [2019ar] => 0 ) [3] => Array ( [month1] => April [2020cs] => 4 [2020as] => 100 [2019cs] => 12 [2019as] => 1400 ) [4] => Array ( [month1] => November [2020cs] => 0 [2020as] => 0 [2019cs] => 7 [2019as] => 200 [2020cr] => 0 [2020ar] => 0 [2019cr] => 1 [2019ar] => 800 ) [5] => Array ( [month1] => December [2020cr] => 0 [2020ar] => 0 [2019cr] => 2 [2019ar] => 500 ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
112.75 ms | 409 KiB | 5 Q