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' => '9:00 AM - 12:00 AM', 'tue' => '9:00 AM - 12:00 AM', 'wed' => '9:00 AM - 12:00 AM', 'thu' => '9:00 AM - 12:00 AM', 'fri' => '9:00 AM - 1:00 AM', 'sat' => '9:00 AM - 1:00 PM, 2:00 PM - 1:00 AM', 'sun' => 'closed' ); // 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";
Output for 5.4.0 - 5.4.26
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /in/JPEKn on line 10
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_DOUBLE_ARROW in /in/JPEKn on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_DOUBLE_ARROW in /in/JPEKn on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/JPEKn on line 10
Process exited with code 255.

preferences:
226.64 ms | 1386 KiB | 116 Q