That should work.
<?php function arrayContainsTime($time, $ranges) { $target = strtotime($time); foreach($ranges as $range) { $start = strtotime($range['start']); $end = strtotime($range['end']); if($target > $start && $target < $end) { return 1; } } return 0; } $at_time = '07:45:00'; $another_time = '10:30:45'; $ranges = [ ['start' => '09:00:00', 'end' => '17:00:00'], ['start' => '17:00:00', 'end' => '08:59:00'] ]; echo $at_time, " match? ", arrayContainsTime($at_time, $ranges); echo "<br>"; echo $another_time, " match? ", arrayContainsTime($another_time, $ranges);
See here in action!
Note: it will not detect 17:00:00 → 08:59:00 correctly, because the date is not specified.
source share