3v4l.org

run code in 300+ PHP versions simultaneously
<?php $times = array( 'mon' => '6:00 AM - 1:00 AM', 'tue' => '6:00 AM - 1:00 AM', 'wed' => '6:00 AM - 1:00 AM', 'thu' => '6:00 AM - 1:00 AM', 'fri' => '6:00 AM - 1:00 AM', 'sat' => '6:00 AM - 2:00 AM', 'sun' => '07:00 PM - 02:00 AM' ); 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(); $open = isOpen($now, $times); if ($open == 0) { echo "Is closed"; } else { echo "Is open. Will close in ".ceil($open/60)." minutes"; } ?>
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.6
Fatal error: Uncaught ArgumentCountError: strtotime() expects at least 1 argument, 0 given in /in/LQLG7:38 Stack trace: #0 /in/LQLG7(38): strtotime() #1 {main} thrown in /in/LQLG7 on line 38
Process exited with code 255.
Output for 5.2.1 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: strtotime() expects at least 1 parameter, 0 given in /in/LQLG7 on line 38 Is closed
Output for 5.1.0 - 5.1.6, 5.2.0
Is closed
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5
Warning: Wrong parameter count for strtotime() in /in/LQLG7 on line 38 Is closed

preferences:
246.17 ms | 402 KiB | 395 Q