3v4l.org

run code in 300+ PHP versions simultaneously
<?php $storeSchedule = [ 'Sun' => ['12:00' => '14:00', '28:00' => '24:00'], 'Mon' => ['09:00' => '12:00'], 'Tue' => ['09:00' => '12:00'], 'Wed' => ['09:00' => '12:00'], 'Thu' => ['09:00' => '12:00'], 'Fri' => ['09:00' => '12:00'], 'Sat' => ['12:00' => '28:00'] ]; // current OR user supplied UNIX timestamp $timestamp = time(); // default status $status = 'closed'; // get current time object $currentTime = (new DateTime())->setTimestamp($timestamp); // loop through time ranges for current day foreach ($storeSchedule[date('D', $timestamp)] as $startTime => $endTime) { // create time objects from start/end times $startTime = DateTime::createFromFormat('h:i A', $startTime); $endTime = DateTime::createFromFormat('h:i A', $endTime); // check if current time is within a range if (($startTime < $currentTime) && ($currentTime < $endTime)) { $status = 'open'; break; } } echo "We are currently: $status";

preferences:
29.39 ms | 402 KiB | 5 Q