3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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'], '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";
based on jdi2s
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 17, Position 2 = 37
Branch analysis from position: 17
Jump found. Position 1 = 18, Position 2 = 37
Branch analysis from position: 18
Jump found. Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
Jump found. Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
Jump found. Position 1 = 37
Branch analysis from position: 37
Jump found. Position 1 = -2
Branch analysis from position: 36
Jump found. Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 33
Branch analysis from position: 37
Branch analysis from position: 37
filename:       /in/9GK6m
function name:  (null)
number of ops:  42
compiled vars:  !0 = $storeSchedule, !1 = $timestamp, !2 = $status, !3 = $currentTime, !4 = $endTime, !5 = $startTime
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   9     0  E >   ASSIGN                                                   !0, <array>
  18     1        INIT_FCALL                                               'time'
         2        DO_ICALL                                         $7      
         3        ASSIGN                                                   !1, $7
  21     4        ASSIGN                                                   !2, 'closed'
  24     5        NEW                                              $10     :-3
         6        DO_FCALL                                      0          
         7        INIT_METHOD_CALL                                         $10, 'setTimestamp'
         8        SEND_VAR_EX                                              !1
         9        DO_FCALL                                      0  $12     
        10        ASSIGN                                                   !3, $12
  27    11        INIT_FCALL                                               'date'
        12        SEND_VAL                                                 'D'
        13        SEND_VAR                                                 !1
        14        DO_ICALL                                         $14     
        15        FETCH_DIM_R                                      $15     !0, $14
        16      > FE_RESET_R                                       $16     $15, ->37
        17    > > FE_FETCH_R                                       ~17     $16, !4, ->37
        18    >   ASSIGN                                                   !5, ~17
  30    19        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
        20        SEND_VAL_EX                                              'h%3Ai+A'
        21        SEND_VAR_EX                                              !5
        22        DO_FCALL                                      0  $19     
        23        ASSIGN                                                   !5, $19
  31    24        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
        25        SEND_VAL_EX                                              'h%3Ai+A'
        26        SEND_VAR_EX                                              !4
        27        DO_FCALL                                      0  $21     
        28        ASSIGN                                                   !4, $21
  34    29        IS_SMALLER                                       ~23     !5, !3
        30      > JMPZ_EX                                          ~23     ~23, ->33
        31    >   IS_SMALLER                                       ~24     !3, !4
        32        BOOL                                             ~23     ~24
        33    > > JMPZ                                                     ~23, ->36
  35    34    >   ASSIGN                                                   !2, 'open'
  36    35      > JMP                                                      ->37
        36    > > JMP                                                      ->17
        37    >   FE_FREE                                                  $16
  40    38        NOP                                                      
        39        FAST_CONCAT                                      ~26     'We+are+currently%3A+', !2
        40        ECHO                                                     ~26
        41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 7.2.0