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 = [ 'Mon' => ['09:00 AM' => '05:00 PM'], 'Tue' => ['09:00 AM' => '05:00 PM'], 'Wed' => ['09:00 AM' => '05:00 PM'], 'Thu' => ['09:00 AM' => '05:00 PM'], 'Fri' => ['09:00 AM' => '05:00 PM'], ]; // current OR user supplied UNIX timestamp $timestamp = 1526731200; // 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 = 15, Position 2 = 35
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 35
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 31
Branch analysis from position: 35
Branch analysis from position: 35
filename:       /in/HRu0q
function name:  (null)
number of ops:  40
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        ASSIGN                                                   !1, 1526731200
   21     2        ASSIGN                                                   !2, 'closed'
   24     3        NEW                                              $9      'DateTime'
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $9, 'setTimestamp'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $11     
          8        ASSIGN                                                   !3, $11
   27     9        INIT_FCALL                                               'date'
         10        SEND_VAL                                                 'D'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $13     
         13        FETCH_DIM_R                                      ~14     !0, $13
         14      > FE_RESET_R                                       $15     ~14, ->35
         15    > > FE_FETCH_R                                       ~16     $15, !4, ->35
         16    >   ASSIGN                                                   !5, ~16
   30    17        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         18        SEND_VAL                                                 'h%3Ai+A'
         19        SEND_VAR                                                 !5
         20        DO_FCALL                                      0  $18     
         21        ASSIGN                                                   !5, $18
   31    22        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         23        SEND_VAL                                                 'h%3Ai+A'
         24        SEND_VAR                                                 !4
         25        DO_FCALL                                      0  $20     
         26        ASSIGN                                                   !4, $20
   34    27        IS_SMALLER                                       ~22     !5, !3
         28      > JMPZ_EX                                          ~22     ~22, ->31
         29    >   IS_SMALLER                                       ~23     !3, !4
         30        BOOL                                             ~22     ~23
         31    > > JMPZ                                                     ~22, ->34
   35    32    >   ASSIGN                                                   !2, 'open'
   36    33      > JMP                                                      ->35
   27    34    > > JMP                                                      ->15
         35    >   FE_FREE                                                  $15
   40    36        NOP                                                      
         37        FAST_CONCAT                                      ~25     'We+are+currently%3A+', !2
         38        ECHO                                                     ~25
         39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.98 ms | 1392 KiB | 15 Q