3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // set timezone to Eastern Time date_default_timezone_set('America/New_York'); $storeSchedule = [ 'Sun' => ['closed'], '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'], 'Sat' => ['closed'] ]; // current or user supplied UNIX timestamp $timestamp = time(); // default status $status = 'open'; // 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 (($currentTime < $startTime) && ($currentTime > $endTime)) { $status = 'closed'; echo '<script>jQuery(function() { offMode(); });</script>'; break; } } echo "We are currently: $status"; echo "<br />"; echo "Server time: " . date('h:i A'); ?>
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
We are currently: open<br />Server time: 01:12 PM
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/JjRRP on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/JjRRP on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/JjRRP on line 5
Process exited with code 255.