3v4l.org

run code in 300+ PHP versions simultaneously
<?php $hours = ["08:00:00", "18:00:00"]; $bookings = [["10:00:00", "15:00:00"], ["08:05:00", "09:00:00"], ["16:00:00", "17:00:00"] ]; $start = $hours[0]; $end = $hours[1]; // sort the bookings $bstart = array_column($bookings, 0); array_multisort($bstart, $bookings); // get the free times $time = $start; $bindex = 0; $free = array(); while ($time < $end && $bindex < count($bookings)) { if ($time < $bookings[$bindex][0]) { $free[] = [$time, $bookings[$bindex][0]]; } $time = $bookings[$bindex][1]; $bindex++; } // end of day free? if ($time < $end) { $free[] = [$time, $end]; } print_r($free);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [0] => 08:00:00 [1] => 08:05:00 ) [1] => Array ( [0] => 09:00:00 [1] => 10:00:00 ) [2] => Array ( [0] => 15:00:00 [1] => 16:00:00 ) [3] => Array ( [0] => 17:00:00 [1] => 18:00:00 ) )

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:
63.21 ms | 402 KiB | 8 Q