3v4l.org

run code in 300+ PHP versions simultaneously
<?php $officialGrid = [ ['grid' => TRUE, 'time' => '08:00', 'content' => NULL], ['grid' => TRUE, 'time' => '09:00', 'content' => NULL] ]; $bookings = [ ['grid' => NULL, 'time' => '08:00', 'content' => 'Paul Simon'], ['grid' => NULL, 'time' => '08:00', 'content' => 'Art Garfunkel'], ['grid' => NULL, 'time' => '08:39', 'content' => 'Homer J. Simpson'] ]; $timeSlotsToDisplay = $officialGrid; array_map(function($el) use(&$timeSlotsToDisplay, $officialGrid) { $timeSlotsToDisplay[$el['time']] = array( 'content' => (isset($timeSlotsToDisplay[$el['time']]) ? trim($timeSlotsToDisplay[$el['time']]['content'], ',') . ',' : '') . $el['content'], 'grid' => isset($officialGrid[$el['time']]) ? true : null ); }, $bookings); ksort($timeSlotsToDisplay); var_export($timeSlotsToDisplay);
Output for 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array ( 0 => array ( 'grid' => true, 'time' => '08:00', 'content' => NULL, ), '08:00' => array ( 'content' => 'Paul Simon,Art Garfunkel', 'grid' => NULL, ), '08:39' => array ( 'content' => 'Homer J. Simpson', 'grid' => NULL, ), 1 => array ( 'grid' => true, 'time' => '09:00', 'content' => NULL, ), )
Output for 8.1.0 - 8.1.34
array ( 0 => array ( 'grid' => true, 'time' => '08:00', 'content' => NULL, ), 1 => array ( 'grid' => true, 'time' => '09:00', 'content' => NULL, ), '08:00' => array ( 'content' => 'Paul Simon,Art Garfunkel', 'grid' => NULL, ), '08:39' => array ( 'content' => 'Homer J. Simpson', 'grid' => NULL, ), )

preferences:
64.8 ms | 1022 KiB | 4 Q