3v4l.org

run code in 300+ PHP versions simultaneously
<?php $storeSchedule = [ 'Sun' => [['12:00' => '01:00', '10:00' => '12:00']], 'Mon' => [['09:00' => '12:00']], 'Tue' => [['09:00' => '12:00']], 'Wed' => [['09:00' => '12:00']], 'Thu' => [['09:00' => '12:00'], ['22:50' => '23:00']], 'Fri' => [['09:00' => '12:00']], 'Sat' => [['12:00' => '01:00', '09:00' => '12:00']] ]; $today = date("D"); $closed = Null; foreach($storeSchedule[$today] as $opentimes){ foreach($opentimes as $open => $close){ $now = time(); if($now > strtotime(date("Y-m-d" . $open)) && $now < strtotime(date("Y-m-d" . $close))){ echo "store open now"; $closed = false; }else if($now < strtotime(date("Y-m-d" . $open))){ echo "store will open at " . date("Y-m-d" . $open); $closed = false; }else{ // Store is closed if($closed !== false) $closed = true; } } } if($closed){ // Dump the next open time $opentime = Key($storeSchedule[date("D",strtotime($today)+86400)][0]); echo "store is closed and will open tomorrow " . $opentime . " and close " . $storeSchedule[date("D",strtotime($today)+86400)][0][$opentime]; }
Output for 5.6.38, 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0, 8.4.4 - 8.4.8
store is closed and will open tomorrow 09:00 and close 12:00

preferences:
73.95 ms | 406 KiB | 5 Q