3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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('18:55pm'); $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
Jump found. Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
Jump found. Position 1 = 23
Branch analysis from position: 23
Jump found. Position 1 = -2
Branch analysis from position: 16
Jump found. Position 1 = -2
filename:       /in/d9P5T
function name:  (null)
number of ops:  24
compiled vars:  !0 = $times, !1 = $now, !2 = $open
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   4     0  E >   ASSIGN                                                   !0, <array>
  13     1        NOP                                                      
  24     2        NOP                                                      
  38     3        INIT_FCALL                                               'strtotime'
         4        SEND_VAL                                                 '18%3A55pm'
         5        DO_ICALL                                         $4      
         6        ASSIGN                                                   !1, $4
  39     7        INIT_FCALL                                               'isopen'
         8        SEND_VAR                                                 !1
         9        SEND_VAR                                                 !0
        10        DO_FCALL                                      0  $6      
        11        ASSIGN                                                   !2, $6
  41    12        IS_EQUAL                                         ~8      !2, 0
        13      > JMPZ                                                     ~8, ->16
  42    14    >   ECHO                                                     'Is+closed'
        15      > JMP                                                      ->23
  44    16    >   INIT_FCALL                                               'ceil'
        17        DIV                                              ~9      !2, 60
        18        SEND_VAL                                                 ~9
        19        DO_ICALL                                         $10     
        20        CONCAT                                           ~11     'Is+open.+Will+close+in+', $10
        21        CONCAT                                           ~12     ~11, '+minutes'
        22        ECHO                                                     ~12
        23    > > RETURN                                                   1

Function compilehours:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
Jump found. Position 1 = -2
Branch analysis from position: 18
Jump found. Position 1 = 80, Position 2 = 95
Branch analysis from position: 80
Jump found. Position 1 = -2
Branch analysis from position: 95
filename:       /in/d9P5T
function name:  compileHours
number of ops:  97
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        INIT_FCALL                                               'count'
        28        SEND_VAR                                                 !2
        29        DO_ICALL                                         $11     
        30        SEND_VAR                                                 $11
        31        SEND_VAL                                                 '-'
        32        DO_ICALL                                         $12     
        33        SEND_VAR                                                 $12
        34        SEND_VAR                                                 !2
        35        DO_ICALL                                         $13     
        36        ASSIGN                                                   !2, $13
  18    37        INIT_FCALL                                               'array_map'
        38        SEND_VAL                                                 'array_map'
        39        INIT_FCALL                                               'array_pad'
        40        SEND_VAL                                                 <array>
        41        INIT_FCALL                                               'count'
        42        SEND_VAR                                                 !2
        43        DO_ICALL                                         $15     
        44        SEND_VAR                                                 $15
        45        SEND_VAL                                                 'strtotime'
        46        DO_ICALL                                         $16     
        47        SEND_VAR                                                 $16
        48        SEND_VAR                                                 !2
        49        INIT_FCALL                                               'array_pad'
        50        SEND_VAL                                                 <array>
        51        INIT_FCALL                                               'count'
        52        SEND_VAR                                                 !2
        53        DO_ICALL                                         $17     
        54        SEND_VAR                                                 $17
        55        INIT_FCALL                                               'array_pad'
        56        SEND_VAL                                                 <array>
        57        SEND_VAL                                                 2
        58        SEND_VAR                                                 !1
        59        DO_ICALL                                         $18     
        60        SEND_VAR                                                 $18
        61        DO_ICALL                                         $19     
        62        SEND_VAR                                                 $19
        63        DO_ICALL                                         $20     
        64        ASSIGN                                                   !2, $20
  19    65        INIT_FCALL                                               'end'
        66        SEND_REF                                                 !2
        67        DO_ICALL                                                 
  20    68        INIT_FCALL                                               'key'
        69        SEND_VAR                                                 !2
        70        DO_ICALL                                         $23     
        71        FETCH_DIM_R                                      $24     !2, $23
        72        FETCH_DIM_R                                      $25     $24, 0
        73        INIT_FCALL                                               'key'
        74        SEND_VAR                                                 !2
        75        DO_ICALL                                         $26     
        76        FETCH_DIM_R                                      $27     !2, $26
        77        FETCH_DIM_R                                      $28     $27, 1
        78        IS_SMALLER                                       ~29     $28, $25
        79      > JMPZ                                                     ~29, ->95
        80    >   INIT_FCALL                                               'key'
        81        SEND_VAR                                                 !2
        82        DO_ICALL                                         $30     
        83        INIT_FCALL                                               'strtotime'
        84        SEND_VAL                                                 '%2B1+day'
        85        INIT_FCALL                                               'key'
        86        SEND_VAR                                                 !2
        87        DO_ICALL                                         $33     
        88        FETCH_DIM_R                                      $34     !2, $33
        89        FETCH_DIM_R                                      $35     $34, 1
        90        SEND_VAR                                                 $35
        91        DO_ICALL                                         $36     
        92        FETCH_DIM_W                                      $31     !2, $30
        93        ASSIGN_DIM                                               $31, 1
        94        OP_DATA                                                  $36
  21    95    > > RETURN                                                   !2
  22    96*     > RETURN                                                   null

End of function compilehours

Function isopen:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 21, Position 2 = 35
Branch analysis from position: 21
Jump found. Position 1 = 22, Position 2 = 35
Branch analysis from position: 22
Jump found. Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
Jump found. Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
Jump found. Position 1 = -2
Branch analysis from position: 34
Jump found. Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 28
Branch analysis from position: 35
Jump found. Position 1 = -2
Branch analysis from position: 35
filename:       /in/d9P5T
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
        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 7.2.0