3v4l.org

run code in 300+ PHP versions simultaneously
<?php $openTimeslots = ['02-09-2021' => [ '8:00-10:00', '16:00-19:00'], '03-09-2021' => [ '7:00-10:00', '16:15-19:00', '14:00-16:00', '13:00-14:15'], '04-09-2021' => [ '7:15-10:00', '15:15-18:15', '18:30-18:45']]; function timeslotsToTimeline($timeslots) { $timeline = []; foreach ($timeslots as $timeslot) { $intTimes = sscanf(str_replace(':', '', $timeslot), "%d-%d"); $timeline[$intTimes[0]] = $intTimes[1]; } return $timeline; } function timelineToTimeslots($timeline) { $timeslots = []; foreach ($timeline as $start => $finish) { $timeslots[] = intdiv($start, 100) . ':' . substr($start, -2) . '-' . intdiv($finish, 100) . ':' . substr($finish, -2); } return $timeslots; } function intersectTimelines($timeline1, $timeline2) { $newTimeline = []; foreach ($timeline1 as $start1 => $finish1) { foreach ($timeline2 as $start2 => $finish2) { $newStart = max($start1, $start2); $newFinish = min($finish1, $finish2); if ($newStart < $newFinish) { $newTimeline[$newStart] = $newFinish; } } } return $newTimeline; } $commonTimeline = timeslotsToTimeline(array_shift($openTimeslots)); foreach ($openTimeslots as $timeslots) { $newTimeline = timeslotsToTimeline($timeslots); $commonTimeline = intersectTimelines($commonTimeline, $newTimeline); } $commonTimeslots = timelineToTimeslots($commonTimeline); var_export($commonTimeslots);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => '8:00-10:00', 1 => '16:15-18:15', 2 => '18:30-18:45', )

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:
111.72 ms | 405 KiB | 5 Q