3v4l.org

run code in 300+ PHP versions simultaneously
<?php $staff = array(1,2,3,4,5); $start = array("11:05", "11:00", "19:00", "13:00", "19:00"); $end = array("20:00", "17:00", "03:00", "20:00", "03:05"); array_multisort($start, $end, $staff); $aloneStart = (strtotime($start[1]) - strtotime($start[0]))/60; // first and second items are the ones that may be working alone at start $aloneEnd = (strtotime($end[count($end)-1]) - strtotime($end[count($end)-2]))/60; // last and second to last are the ones that may be working alone at end if($aloneStart > 0){ $staffAloneStart = $staff[0]; //must be the first who worked alone echo "minutes alone at start: " . $aloneStart . " and it was " . $staffAloneStart . "\n"; } if($aloneEnd > 0){ $staffAloneEnd = $staff[count($end)-1]; // must be the last to end that worked alone echo "minutes alone at end: " . $aloneEnd . " and it was " . $staffAloneEnd . "\n"; } $aloneTime = intval($aloneStart)+intval($aloneEnd); echo "total time alone " . $aloneTime;
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
minutes alone at start: 5 and it was 2 minutes alone at end: 5 and it was 5 total time alone 10

preferences:
251.58 ms | 404 KiB | 292 Q