3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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' => '9:00 AM - 1:00 PM, 2:00 PM - 1:00 AM', '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; } echo isOpen('5:29 pm');
based on crNNa
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function isOpen(), 1 passed in /in/EKblu on line 37 and exactly 2 expected in /in/EKblu:24 Stack trace: #0 /in/EKblu(37): isOpen('5:29 pm') #1 {main} thrown in /in/EKblu on line 24
Process exited with code 255.
Output for 5.4.0 - 7.0.20
Warning: Missing argument 2 for isOpen(), called in /in/EKblu on line 37 and defined in /in/EKblu on line 24 Notice: Undefined variable: times in /in/EKblu on line 27 Notice: A non well formed numeric value encountered in /in/EKblu on line 27 Notice: Undefined variable: times in /in/EKblu on line 27 Notice: A non well formed numeric value encountered in /in/EKblu on line 14 0