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'], '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'] ]; // 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";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 37
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 37
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 42) 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/PFqHC
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>
   20     1        INIT_FCALL                                               'time'
          2        DO_ICALL                                         $7      
          3        ASSIGN                                                   !1, $7
   23     4        ASSIGN                                                   !2, 'closed'
   26     5        NEW                                              $10     'DateTime'
          6        DO_FCALL                                      0          
          7        INIT_METHOD_CALL                                         $10, 'setTimestamp'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0  $12     
         10        ASSIGN                                                   !3, $12
   29    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
   32    19        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         20        SEND_VAL                                                 'h%3Ai+A'
         21        SEND_VAR                                                 !5
         22        DO_FCALL                                      0  $19     
         23        ASSIGN                                                   !5, $19
   33    24        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         25        SEND_VAL                                                 'h%3Ai+A'
         26        SEND_VAR                                                 !4
         27        DO_FCALL                                      0  $21     
         28        ASSIGN                                                   !4, $21
   36    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
   37    34    >   ASSIGN                                                   !2, 'open'
   38    35      > JMP                                                      ->37
   29    36    > > JMP                                                      ->17
         37    >   FE_FREE                                                  $16
   42    38        NOP                                                      
         39        FAST_CONCAT                                      ~26     'We+are+currently%3A+', !2
         40        ECHO                                                     ~26
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.96 ms | 1392 KiB | 17 Q