0

how can i check if the current time is in a break time or not using php ? i need to search within the below array if for example the current time is between any of the start/end date of any break

$current = date('Y-m-d H:i:s');

Array
(
    [0] => Array
        (
            [break] => 1
            [start] => 2017-10-10 16:32:00
            [end] => 2017-10-12 14:54:33
        )

    [1] => Array
        (
            [break] => 2
            [start] => 2017-10-16 14:54:33
            [end] => 2017-10-18 23:55:00
        )

)
mirvatJ
  • 366
  • 1
  • 3
  • 15

1 Answers1

0
foreach ($items as $item) {
    if ($item->start <= $current && $item->end >= $current) {
        // Do stuff
    }
}

or...

$items = array_filter($items, function($item) {
    return ($item->start <= $current && $item->end >= $current);
});