3v4l.org

run code in 300+ PHP versions simultaneously
<?php $times = array( 'mon' => '6:00 AM - 1:00 AM', 'tue' => '6:00 AM - 1:00 AM', 'wed' => '6:00 AM - 1:00 AM', 'thu' => '6:00 AM - 1:00 AM', 'fri' => '6:00 AM - 1:00 AM', 'sat' => '6:00 AM - 2:00 AM', 'sun' => '07:00 PM - 02:00 AM' ); function compileHours($times, $timestamp) { $times = $times[strtolower(date('D',$timestamp))]; if(!strpos($times, '-')) return array(); $hours = explode(",", $times); $hours = array_map('explode', array_pad(array(),count($hours),'-'), $hours); $hours = array_map('array_map', array_pad(array(),count($hours),'strtotime'), $hours, array_pad(array(),count($hours),array_pad(array(),2,$timestamp))); end($hours); if ($hours[key($hours)][0] > $hours[key($hours)][1]) $hours[key($hours)][1] = strtotime('+1 day', $hours[key($hours)][1]); return $hours; } function isOpen($now, $times) { $open = 0; // time until closing in seconds or 0 if closed // merge opening hours of today and the day before $hours = array_merge(compileHours($times, strtotime('yesterday',$now)),compileHours($times, $now)); foreach ($hours as $h) { if ($now >= $h[0] and $now < $h[1]) { $open = $h[1] - $now; return $open; } } return $open; } $now = strtotime('7:59pm'); $open = isOpen($now, $times); if ($open == 0) { echo "Is closed"; } else { echo "Is open. Will close in ".ceil($open/60)." minutes"; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1ECid
function name:  (null)
number of ops:  22
compiled vars:  !0 = $times, !1 = $now, !2 = $open
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   38     1        INIT_FCALL                                               'strtotime'
          2        SEND_VAL                                                 '7%3A59pm'
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   39     5        INIT_FCALL                                               'isopen'
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !2, $6
   41    10        IS_EQUAL                                                 !2, 0
         11      > JMPZ                                                     ~8, ->14
   42    12    >   ECHO                                                     'Is+closed'
         13      > JMP                                                      ->21
   44    14    >   INIT_FCALL                                               'ceil'
         15        DIV                                              ~9      !2, 60
         16        SEND_VAL                                                 ~9
         17        DO_ICALL                                         $10     
         18        CONCAT                                           ~11     'Is+open.+Will+close+in+', $10
         19        CONCAT                                           ~12     ~11, '+minutes'
         20        ECHO                                                     ~12
   47    21    > > RETURN                                                   1

Function compilehours:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 89
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 89
filename:       /in/1ECid
function name:  compileHours
number of ops:  91
compiled vars:  !0 = $times, !1 = $timestamp, !2 = $hours
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_FCALL                                               'strtolower'
          3        INIT_FCALL                                               'date'
          4        SEND_VAL                                                 'D'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        SEND_VAR                                                 $3
          8        DO_ICALL                                         $4      
          9        FETCH_DIM_R                                      ~5      !0, $4
         10        ASSIGN                                                   !0, ~5
   15    11        INIT_FCALL                                               'strpos'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 '-'
         14        DO_ICALL                                         $7      
         15        BOOL_NOT                                         ~8      $7
         16      > JMPZ                                                     ~8, ->18
         17    > > RETURN                                                   <array>
   16    18    >   INIT_FCALL                                               'explode'
         19        SEND_VAL                                                 '%2C'
         20        SEND_VAR                                                 !0
         21        DO_ICALL                                         $9      
         22        ASSIGN                                                   !2, $9
   17    23        INIT_FCALL                                               'array_map'
         24        SEND_VAL                                                 'explode'
         25        INIT_FCALL                                               'array_pad'
         26        SEND_VAL                                                 <array>
         27        COUNT                                            ~11     !2
         28        SEND_VAL                                                 ~11
         29        SEND_VAL                                                 '-'
         30        DO_ICALL                                         $12     
         31        SEND_VAR                                                 $12
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                         $13     
         34        ASSIGN                                                   !2, $13
   18    35        INIT_FCALL                                               'array_map'
         36        SEND_VAL                                                 'array_map'
         37        INIT_FCALL                                               'array_pad'
         38        SEND_VAL                                                 <array>
         39        COUNT                                            ~15     !2
         40        SEND_VAL                                                 ~15
         41        SEND_VAL                                                 'strtotime'
         42        DO_ICALL                                         $16     
         43        SEND_VAR                                                 $16
         44        SEND_VAR                                                 !2
         45        INIT_FCALL                                               'array_pad'
         46        SEND_VAL                                                 <array>
         47        COUNT                                            ~17     !2
         48        SEND_VAL                                                 ~17
         49        INIT_FCALL                                               'array_pad'
         50        SEND_VAL                                                 <array>
         51        SEND_VAL                                                 2
         52        SEND_VAR                                                 !1
         53        DO_ICALL                                         $18     
         54        SEND_VAR                                                 $18
         55        DO_ICALL                                         $19     
         56        SEND_VAR                                                 $19
         57        DO_ICALL                                         $20     
         58        ASSIGN                                                   !2, $20
   19    59        INIT_FCALL                                               'end'
         60        SEND_REF                                                 !2
         61        DO_ICALL                                                 
   20    62        INIT_FCALL                                               'key'
         63        SEND_VAR                                                 !2
         64        DO_ICALL                                         $23     
         65        FETCH_DIM_R                                      ~24     !2, $23
         66        FETCH_DIM_R                                      ~25     ~24, 0
         67        INIT_FCALL                                               'key'
         68        SEND_VAR                                                 !2
         69        DO_ICALL                                         $26     
         70        FETCH_DIM_R                                      ~27     !2, $26
         71        FETCH_DIM_R                                      ~28     ~27, 1
         72        IS_SMALLER                                               ~28, ~25
         73      > JMPZ                                                     ~29, ->89
         74    >   INIT_FCALL                                               'key'
         75        SEND_VAR                                                 !2
         76        DO_ICALL                                         $30     
         77        INIT_FCALL                                               'strtotime'
         78        SEND_VAL                                                 '%2B1+day'
         79        INIT_FCALL                                               'key'
         80        SEND_VAR                                                 !2
         81        DO_ICALL                                         $33     
         82        FETCH_DIM_R                                      ~34     !2, $33
         83        FETCH_DIM_R                                      ~35     ~34, 1
         84        SEND_VAL                                                 ~35
         85        DO_ICALL                                         $36     
         86        FETCH_DIM_W                                      $31     !2, $30
         87        ASSIGN_DIM                                               $31, 1
         88        OP_DATA                                                  $36
   21    89    > > RETURN                                                   !2
   22    90*     > RETURN                                                   null

End of function compilehours

Function isopen:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 35
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 35
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 28
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/1ECid
function name:  isOpen
number of ops:  38
compiled vars:  !0 = $now, !1 = $times, !2 = $open, !3 = $hours, !4 = $h
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        ASSIGN                                                   !2, 0
   27     3        INIT_FCALL                                               'array_merge'
          4        INIT_FCALL                                               'compilehours'
          5        SEND_VAR                                                 !1
          6        INIT_FCALL                                               'strtotime'
          7        SEND_VAL                                                 'yesterday'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        SEND_VAR                                                 $6
         11        DO_FCALL                                      0  $7      
         12        SEND_VAR                                                 $7
         13        INIT_FCALL                                               'compilehours'
         14        SEND_VAR                                                 !1
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0  $8      
         17        SEND_VAR                                                 $8
         18        DO_ICALL                                         $9      
         19        ASSIGN                                                   !3, $9
   29    20      > FE_RESET_R                                       $11     !3, ->35
         21    > > FE_FETCH_R                                               $11, !4, ->35
   30    22    >   FETCH_DIM_R                                      ~12     !4, 0
         23        IS_SMALLER_OR_EQUAL                              ~13     ~12, !0
         24      > JMPZ_EX                                          ~13     ~13, ->28
         25    >   FETCH_DIM_R                                      ~14     !4, 1
         26        IS_SMALLER                                       ~15     !0, ~14
         27        BOOL                                             ~13     ~15
         28    > > JMPZ                                                     ~13, ->34
   31    29    >   FETCH_DIM_R                                      ~16     !4, 1
         30        SUB                                              ~17     ~16, !0
         31        ASSIGN                                                   !2, ~17
   32    32        FE_FREE                                                  $11
         33      > RETURN                                                   !2
   29    34    > > JMP                                                      ->21
         35    >   FE_FREE                                                  $11
   35    36      > RETURN                                                   !2
   36    37*     > RETURN                                                   null

End of function isopen

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.2 ms | 1402 KiB | 38 Q