3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Based on the following business hours: * (Note : I setup the hours for each day if they carry-over) * everyday is open from 09:00 AM - 12:00 AM * Sun/Sat open extra from 12:00 AM - 01:00 AM */ $storeSchedule = [ 'Mon' => ['09:00 AM' => '05:00 PM'], 'Tue' => ['09:00 AM' => '05:00 PM'], 'Wed' => ['09:00 AM' => '05:00 PM'], 'Thu' => ['09:00 AM' => '05:00 PM'], 'Fri' => ['09:00 AM' => '05:00 PM'], ]; // current OR user supplied UNIX timestamp $timestamp = 1526731200; // 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";
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key "Sat" in /in/HRu0q on line 27 Warning: foreach() argument must be of type array|object, null given in /in/HRu0q on line 27 We are currently: closed
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key "Sat" in /in/HRu0q on line 27 Warning: foreach() argument must be of type array|object, null given in /in/HRu0q on line 27 We are currently: closed
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.31, 7.4.0 - 7.4.33
Notice: Undefined index: Sat in /in/HRu0q on line 27 Warning: Invalid argument supplied for foreach() in /in/HRu0q on line 27 We are currently: closed
Output for 7.3.32 - 7.3.33
Warning: Invalid argument supplied for foreach() in /in/HRu0q on line 27 We are currently: closed

preferences:
219.27 ms | 401 KiB | 284 Q