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 = [ 'Sun' => ['12:00 AM' => '01:00 AM', '09:00 AM' => '12:00 AM'], 'Mon' => ['09:00 AM' => '12:00 AM'], 'Tue' => ['09:00 AM' => '12:00 AM'], 'Wed' => ['09:00 AM' => '12:00 AM'], 'Thu' => ['09:00 AM' => '12:00 AM'],<?php $times = array( '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' => 'closed', 'sun' => 'closed' ); function compileHours($times, $timestamp) { $times = $times[strtolower(date('D',$timestamp))]; if(!strpos($times, '-')) return array(); $hours = explode(",", $times); $hours = array_map('explode', array_pad(array(),count($hours),'-'), $hours); $hours = array_map('array_map', array_pad(array(),count($hours),'strtotime'), $hours, array_pad(array(),count($hours),array_pad(array(),2,$timestamp))); end($hours); if ($hours[key($hours)][0] > $hours[key($hours)][1]) $hours[key($hours)][1] = strtotime('+1 day', $hours[key($hours)][1]); return $hours; } function isOpen($now, $times) { $open = 0; // time until closing in seconds or 0 if closed // merge opening hours of today and the day before $hours = array_merge(compileHours($times, strtotime('yesterday',$now)),compileHours($times, $now)); foreach ($hours as $h) { if ($now >= $h[0] and $now < $h[1]) { $open = $h[1] - $now; return $open; } } return $open; } $now = strtotime('7:59pm'); $open = isOpen($now, $times); if ($open == 0) { echo "Is closed"; } else { echo "Is open. Will close in ".ceil($open/60)." minutes"; } ?> 'Fri' => ['09:00 AM' => '12:00 AM'], 'Sat' => ['12:00 AM' => '01:00 AM', '09:00 AM' => '12:00 AM'] ]; // 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";

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.310.0060.04212.50
5.4.300.0020.04112.50
5.4.290.0070.03912.49
5.4.280.0090.03312.39
5.4.270.0080.03512.39
5.4.260.0070.03612.39
5.4.250.0030.04012.39
5.4.240.0060.03612.39
5.4.230.0050.03912.38
5.4.220.0040.03812.38
5.4.210.0080.03312.39
5.4.200.0090.03412.39
5.4.190.0060.03612.38
5.4.180.0040.04912.38
5.4.170.0070.03612.39
5.4.160.0100.04112.39
5.4.150.0050.03812.38
5.4.140.0060.03712.07
5.4.130.0060.03612.05
5.4.120.0050.03612.02
5.4.110.0120.02912.02
5.4.100.0030.03812.02
5.4.90.0080.03512.01
5.4.80.0050.03812.01
5.4.70.0040.03612.01
5.4.60.0070.03412.01
5.4.50.0050.03512.00
5.4.40.0080.03211.99
5.4.30.0070.03611.99
5.4.20.0080.03311.99
5.4.10.0060.03511.99
5.4.00.0060.03511.48
5.3.280.0030.04112.71
5.3.270.0020.04312.73
5.3.260.0050.03912.72
5.3.250.0040.03912.72
5.3.240.0090.03312.72
5.3.230.0080.04112.71
5.3.220.0010.04212.68
5.3.210.0060.03912.68
5.3.200.0080.03512.68
5.3.190.0060.03712.68
5.3.180.0080.03412.68
5.3.170.0050.03712.67
5.3.160.0100.03212.68
5.3.150.0070.03612.67
5.3.140.0060.03712.66
5.3.130.0060.03812.66
5.3.120.0080.03712.66
5.3.110.0030.04212.66
5.3.100.0090.03512.12
5.3.90.0080.04112.08
5.3.80.0020.03912.08
5.3.70.0030.03912.07
5.3.60.0060.03612.06
5.3.50.0040.03812.00
5.3.40.0090.03412.00
5.3.30.0060.03511.95
5.3.20.0060.03511.73
5.3.10.0060.03511.70
5.3.00.0060.03611.68
5.2.170.0010.0359.19
5.2.160.0050.0299.18
5.2.150.0070.0289.19
5.2.140.0060.0319.18
5.2.130.0030.0319.14
5.2.120.0040.0309.14
5.2.110.0050.0319.15
5.2.100.0060.0349.14
5.2.90.0030.0329.15
5.2.80.0040.0319.14
5.2.70.0050.0319.14
5.2.60.0050.0319.09
5.2.50.0060.0379.06
5.2.40.0050.0309.04
5.2.30.0050.0309.01
5.2.20.0070.0259.00
5.2.10.0070.0258.93
5.2.00.0050.0368.79
5.1.60.0050.0248.07
5.1.50.0040.0328.07
5.1.40.0040.0258.05
5.1.30.0050.0328.39
5.1.20.0050.0318.42
5.1.10.0040.0278.14
5.1.00.0030.0288.14
5.0.50.0060.0196.63
5.0.40.0050.0186.48
5.0.30.0030.0336.30
5.0.20.0070.0176.26
5.0.10.0050.0276.24
5.0.00.0080.0356.23
4.4.90.0080.0184.77
4.4.80.0050.0184.75
4.4.70.0040.0244.76
4.4.60.0070.0204.76
4.4.50.0020.0184.77
4.4.40.0030.0264.71
4.4.30.0020.0174.76
4.4.20.0010.0174.84
4.4.10.0030.0154.85
4.4.00.0070.0284.76
4.3.110.0050.0154.67
4.3.100.0040.0204.66
4.3.90.0050.0184.63
4.3.80.0060.0284.58
4.3.70.0050.0184.63
4.3.60.0030.0204.63
4.3.50.0040.0184.63
4.3.40.0040.0234.53
4.3.30.0010.0193.29
4.3.20.0020.0163.26
4.3.10.0030.0223.22
4.3.00.0000.0237.21

preferences:
142.08 ms | 1394 KiB | 7 Q