3v4l.org

run code in 300+ PHP versions simultaneously
<?php $times = array( 'mon' => '9:00 AM - 12:00 AM', 'tue' => '9:00 AM - 12:00 AM', 'wed' => '9:00 AM - 12:00 AM', 'thu' => '9:00 AM - 12:00 AM', 'fri' => '9:00 AM - 1:00 AM', 'sat' => 'closed', 'sun' => 'closed' ); function compileHours($times, $timezone) { $times = $times[strtolower(date('D',$timezone))]; 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/DDLeq
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/DDLeq
function name:  compileHours
number of ops:  91
compiled vars:  !0 = $times, !1 = $timezone, !2 = $hours, !3 = $timestamp
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                                         $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                         $5      
          9        FETCH_DIM_R                                      ~6      !0, $5
         10        ASSIGN                                                   !0, ~6
   15    11        INIT_FCALL                                               'strpos'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 '-'
         14        DO_ICALL                                         $8      
         15        BOOL_NOT                                         ~9      $8
         16      > JMPZ                                                     ~9, ->18
         17    > > RETURN                                                   <array>
   16    18    >   INIT_FCALL                                               'explode'
         19        SEND_VAL                                                 '%2C'
         20        SEND_VAR                                                 !0
         21        DO_ICALL                                         $10     
         22        ASSIGN                                                   !2, $10
   17    23        INIT_FCALL                                               'array_map'
         24        SEND_VAL                                                 'explode'
         25        INIT_FCALL                                               'array_pad'
         26        SEND_VAL                                                 <array>
         27        COUNT                                            ~12     !2
         28        SEND_VAL                                                 ~12
         29        SEND_VAL                                                 '-'
         30        DO_ICALL                                         $13     
         31        SEND_VAR                                                 $13
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                         $14     
         34        ASSIGN                                                   !2, $14
   18    35        INIT_FCALL                                               'array_map'
         36        SEND_VAL                                                 'array_map'
         37        INIT_FCALL                                               'array_pad'
         38        SEND_VAL                                                 <array>
         39        COUNT                                            ~16     !2
         40        SEND_VAL                                                 ~16
         41        SEND_VAL                                                 'strtotime'
         42        DO_ICALL                                         $17     
         43        SEND_VAR                                                 $17
         44        SEND_VAR                                                 !2
         45        INIT_FCALL                                               'array_pad'
         46        SEND_VAL                                                 <array>
         47        COUNT                                            ~18     !2
         48        SEND_VAL                                                 ~18
         49        INIT_FCALL                                               'array_pad'
         50        SEND_VAL                                                 <array>
         51        SEND_VAL                                                 2
         52        SEND_VAR                                                 !3
         53        DO_ICALL                                         $19     
         54        SEND_VAR                                                 $19
         55        DO_ICALL                                         $20     
         56        SEND_VAR                                                 $20
         57        DO_ICALL                                         $21     
         58        ASSIGN                                                   !2, $21
   19    59        INIT_FCALL                                               'end'
         60        SEND_REF                                                 !2
         61        DO_ICALL                                                 
   20    62        INIT_FCALL                                               'key'
         63        SEND_VAR                                                 !2
         64        DO_ICALL                                         $24     
         65        FETCH_DIM_R                                      ~25     !2, $24
         66        FETCH_DIM_R                                      ~26     ~25, 0
         67        INIT_FCALL                                               'key'
         68        SEND_VAR                                                 !2
         69        DO_ICALL                                         $27     
         70        FETCH_DIM_R                                      ~28     !2, $27
         71        FETCH_DIM_R                                      ~29     ~28, 1
         72        IS_SMALLER                                               ~29, ~26
         73      > JMPZ                                                     ~30, ->89
         74    >   INIT_FCALL                                               'key'
         75        SEND_VAR                                                 !2
         76        DO_ICALL                                         $31     
         77        INIT_FCALL                                               'strtotime'
         78        SEND_VAL                                                 '%2B1+day'
         79        INIT_FCALL                                               'key'
         80        SEND_VAR                                                 !2
         81        DO_ICALL                                         $34     
         82        FETCH_DIM_R                                      ~35     !2, $34
         83        FETCH_DIM_R                                      ~36     ~35, 1
         84        SEND_VAL                                                 ~36
         85        DO_ICALL                                         $37     
         86        FETCH_DIM_W                                      $32     !2, $31
         87        ASSIGN_DIM                                               $32, 1
         88        OP_DATA                                                  $37
   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/DDLeq
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:
158.46 ms | 1402 KiB | 38 Q