3v4l.org

run code in 300+ PHP versions simultaneously
<?php $storeSchedule = [ 'Sun' => ['12:00' => '14:00', '28:00' => '24:00'], 'Mon' => ['09:00' => '12:00'], 'Tue' => ['09:00' => '12:00'], 'Wed' => ['09:00' => '12:00'], 'Thu' => ['09:00' => '12:00', '14:00' => '24:00'], 'Fri' => ['09:00' => '12:00'], 'Sat' => ['12:00' => '28:00'] ]; // 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', $startTime); $endTime = DateTime::createFromFormat('h:i', $endTime); // check if current time is within a range if (($startTime < $currentTime) && ($currentTime < $endTime)) { $status = 'open'; break; } } echo "We are currently: $status $timestamp";
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/UvdOZ
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
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'time'
          2        DO_ICALL                                         $7      
          3        ASSIGN                                                   !1, $7
   16     4        ASSIGN                                                   !2, 'closed'
   19     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
   22    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
   25    19        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         20        SEND_VAL                                                 'h%3Ai'
         21        SEND_VAR                                                 !5
         22        DO_FCALL                                      0  $19     
         23        ASSIGN                                                   !5, $19
   26    24        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         25        SEND_VAL                                                 'h%3Ai'
         26        SEND_VAR                                                 !4
         27        DO_FCALL                                      0  $21     
         28        ASSIGN                                                   !4, $21
   29    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
   30    34    >   ASSIGN                                                   !2, 'open'
   31    35      > JMP                                                      ->37
   22    36    > > JMP                                                      ->17
         37    >   FE_FREE                                                  $16
   35    38        ROPE_INIT                                     4  ~27     'We+are+currently%3A+'
         39        ROPE_ADD                                      1  ~27     ~27, !2
         40        ROPE_ADD                                      2  ~27     ~27, '+'
         41        ROPE_END                                      3  ~26     ~27, !1
         42        ECHO                                                     ~26
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.28 ms | 1392 KiB | 17 Q