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'], 'Fri' => ['09:00 AM' => '12:00 AM'], 'Sat' => ['12:00 AM' => '01:00 AM', '09:00 AM' => '12:00 AM'] ]; date_default_timezone_set('america/chicago'); // 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 "$currentTime";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 40
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 40
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 36
Branch analysis from position: 40
Branch analysis from position: 40
filename:       /in/O7OhA
function name:  (null)
number of ops:  44
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                                               'date_default_timezone_set'
          2        SEND_VAL                                                 'america%2Fchicago'
          3        DO_ICALL                                                 
   20     4        INIT_FCALL                                               'time'
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !1, $8
   23     7        ASSIGN                                                   !2, 'closed'
   26     8        NEW                                              $11     'DateTime'
          9        DO_FCALL                                      0          
         10        INIT_METHOD_CALL                                         $11, 'setTimestamp'
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0  $13     
         13        ASSIGN                                                   !3, $13
   29    14        INIT_FCALL                                               'date'
         15        SEND_VAL                                                 'D'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $15     
         18        FETCH_DIM_R                                      ~16     !0, $15
         19      > FE_RESET_R                                       $17     ~16, ->40
         20    > > FE_FETCH_R                                       ~18     $17, !4, ->40
         21    >   ASSIGN                                                   !5, ~18
   32    22        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         23        SEND_VAL                                                 'h%3Ai+A'
         24        SEND_VAR                                                 !5
         25        DO_FCALL                                      0  $20     
         26        ASSIGN                                                   !5, $20
   33    27        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         28        SEND_VAL                                                 'h%3Ai+A'
         29        SEND_VAR                                                 !4
         30        DO_FCALL                                      0  $22     
         31        ASSIGN                                                   !4, $22
   36    32        IS_SMALLER                                       ~24     !5, !3
         33      > JMPZ_EX                                          ~24     ~24, ->36
         34    >   IS_SMALLER                                       ~25     !3, !4
         35        BOOL                                             ~24     ~25
         36    > > JMPZ                                                     ~24, ->39
   37    37    >   ASSIGN                                                   !2, 'open'
   38    38      > JMP                                                      ->40
   29    39    > > JMP                                                      ->20
         40    >   FE_FREE                                                  $17
   42    41        CAST                                          6  ~27     !3
         42        ECHO                                                     ~27
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.5 ms | 1400 KiB | 19 Q