3v4l.org

run code in 300+ PHP versions simultaneously
<?php $newArr = array ( 100 => array ( 1 => array ( 'AVA_Date' => '2019-04-18', 'ROO_Id' => 100, 'RAT_Id' => 9 ), 2 => array ( 'AVA_Date' => '2019-04-20', 'ROO_Id' => 100, 'RAT_Id' => 10 ), 4 => array ( 'AVA_Date' => '2019-04-21', 'ROO_Id' => 100, 'RAT_Id' => 10 ), 7 => array ( 'AVA_Date' => '2019-04-22', 'ROO_Id' => 100, 'RAT_Id' => 9 ) ) ); foreach ($newArr as $key => $array) { $newArrOtherRooms[$key] = array_reduce($array, function($acc, $val) { $room = array_keys(array_column($acc, 'ROO_Id'), $val['ROO_Id']); $rate = array_keys(array_column($acc, 'RAT_Id'), $val['RAT_Id']); $common = array_intersect($room, $rate); if(!empty($common)) { array_push($acc[current($common)]['AVA_Date'], $val['AVA_Date']); } else { $new_arr = $val; $new_arr['AVA_Date'] = [$val['AVA_Date']]; array_push($acc, $new_arr); } return $acc; },[]); } print_r($newArrOtherRooms);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [100] => Array ( [0] => Array ( [AVA_Date] => Array ( [0] => 2019-04-18 [1] => 2019-04-22 ) [ROO_Id] => 100 [RAT_Id] => 9 ) [1] => Array ( [AVA_Date] => Array ( [0] => 2019-04-20 [1] => 2019-04-21 ) [ROO_Id] => 100 [RAT_Id] => 10 ) ) )

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:
27.58 ms | 405 KiB | 8 Q