3v4l.org

run code in 300+ PHP versions simultaneously
<?php function setting($v) { $db = [ 'opening_time_Sunday' => '10:30', 'closing_time_Sunday' => '00:00', 'opening_time_Monday' => '09:30', 'closing_time_Monday' => '01:30', 'opening_time_Tuesday' => '09:30', 'closing_time_Tuesday' => '01:30', 'opening_time_Wednesday' => '09:30', 'closing_time_Wednesday' => '01:30', 'opening_time_Thursday' => '09:30', 'closing_time_Thursday' => '01:30', 'opening_time_Friday' => '09:30', 'closing_time_Friday' => '23:00', 'opening_time_Saturday' => '10:30', 'closing_time_Saturday' => '00:00', ]; return $db[$v]; } function Today($dateString = null) { $currentDate = new \DateTimeImmutable($dateString); $priorDate = $currentDate->sub(new \DateInterval('P1D')); $yesterday = $priorDate->format('l'); $priorClosing = setting('closing_time_' . $yesterday); $closeDate = $currentDate->setTime(...explode(':', $priorClosing)); if ($closeDate->format('a') === 'am' && $currentDate < $closeDate) { //check if the the closing has not occurred yet $currentDate = $priorDate; } $today = $currentDate->format('l'); $start = setting('opening_time_' . $today); $end = setting('closing_time_' . $today); return $today . ': ' . $start . " - " . $end; } $dates = []; for ($i=0;$i<7;$i++) { $date = \date_create('2018-10-08'); if ($i > 0) { $date->modify('+' . $i . ' day'); } $dates[$date->format('l')] = [ '00:15' => Today($date->setTime(0, 15)->format('Y-m-d H:i:s')), '23:00' => Today($date->setTime(23, 0, 0)->format('Y-m-d H:i:s')) ]; } echo "Day \t|\t00:15:00\t\t\t|\t23:00:00\n"; foreach($dates as $day => $times) { echo "$day \t|\t{$times['00:15']} \t|\t{$times['23:00']}\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 3
Branch analysis from position: 45
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 59
Branch analysis from position: 47
2 jumps found. (Code = 78) Position 1 = 48, Position 2 = 59
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 3
Branch analysis from position: 45
Branch analysis from position: 3
Branch analysis from position: 14
filename:       /in/Cs6jS
function name:  (null)
number of ops:  61
compiled vars:  !0 = $dates, !1 = $i, !2 = $date, !3 = $times, !4 = $day
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   ASSIGN                                                   !0, <array>
   50     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->43
   51     3    >   INIT_FCALL                                               'date_create'
          4        SEND_VAL                                                 '2018-10-08'
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !2, $7
   52     7        IS_SMALLER                                               0, !1
          8      > JMPZ                                                     ~9, ->14
   53     9    >   INIT_METHOD_CALL                                         !2, 'modify'
         10        CONCAT                                           ~10     '%2B', !1
         11        CONCAT                                           ~11     ~10, '+day'
         12        SEND_VAL_EX                                              ~11
         13        DO_FCALL                                      0          
   55    14    >   INIT_METHOD_CALL                                         !2, 'format'
         15        SEND_VAL_EX                                              'l'
         16        DO_FCALL                                      0  $13     
   56    17        INIT_FCALL                                               'today'
         18        INIT_METHOD_CALL                                         !2, 'setTime'
         19        SEND_VAL_EX                                              0
         20        SEND_VAL_EX                                              15
         21        DO_FCALL                                      0  $15     
         22        INIT_METHOD_CALL                                         $15, 'format'
         23        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         24        DO_FCALL                                      0  $16     
         25        SEND_VAR                                                 $16
         26        DO_FCALL                                      0  $17     
         27        INIT_ARRAY                                       ~18     $17, '00%3A15'
   57    28        INIT_FCALL                                               'today'
         29        INIT_METHOD_CALL                                         !2, 'setTime'
         30        SEND_VAL_EX                                              23
         31        SEND_VAL_EX                                              0
         32        SEND_VAL_EX                                              0
         33        DO_FCALL                                      0  $19     
         34        INIT_METHOD_CALL                                         $19, 'format'
         35        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         36        DO_FCALL                                      0  $20     
         37        SEND_VAR                                                 $20
         38        DO_FCALL                                      0  $21     
         39        ADD_ARRAY_ELEMENT                                ~18     $21, '23%3A00'
   55    40        ASSIGN_DIM                                               !0, $13
   57    41        OP_DATA                                                  ~18
   50    42        PRE_INC                                                  !1
         43    >   IS_SMALLER                                               !1, 7
         44      > JMPNZ                                                    ~23, ->3
   60    45    >   ECHO                                                     'Day+++++++++%09%7C%0900%3A15%3A00%09%09%09%7C%0923%3A00%3A00%0A'
   61    46      > FE_RESET_R                                       $24     !0, ->59
         47    > > FE_FETCH_R                                       ~25     $24, !3, ->59
         48    >   ASSIGN                                                   !4, ~25
   62    49        ROPE_INIT                                     6  ~30     !4
         50        ROPE_ADD                                      1  ~30     ~30, '++%09%7C%09'
         51        FETCH_DIM_R                                      ~27     !3, '00%3A15'
         52        ROPE_ADD                                      2  ~30     ~30, ~27
         53        ROPE_ADD                                      3  ~30     ~30, '++++%09%7C%09'
         54        FETCH_DIM_R                                      ~28     !3, '23%3A00'
         55        ROPE_ADD                                      4  ~30     ~30, ~28
         56        ROPE_END                                      5  ~29     ~30, '%0A'
         57        ECHO                                                     ~29
   61    58      > JMP                                                      ->47
         59    >   FE_FREE                                                  $24
   63    60      > RETURN                                                   1

Function setting:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cs6jS
function name:  setting
number of ops:  5
compiled vars:  !0 = $v, !1 = $db
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
   22     2        FETCH_DIM_R                                      ~3      !1, !0
          3      > RETURN                                                   ~3
   24     4*     > RETURN                                                   null

End of function setting

Function today:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
Branch analysis from position: 37
filename:       /in/Cs6jS
function name:  Today
number of ops:  59
compiled vars:  !0 = $dateString, !1 = $currentDate, !2 = $priorDate, !3 = $yesterday, !4 = $priorClosing, !5 = $closeDate, !6 = $today, !7 = $start, !8 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV_INIT                                        !0      null
   28     1        NEW                                              $9      'DateTimeImmutable'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $9
   30     5        INIT_METHOD_CALL                                         !1, 'sub'
          6        NEW                                              $12     'DateInterval'
          7        SEND_VAL_EX                                              'P1D'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $12
         10        DO_FCALL                                      0  $14     
         11        ASSIGN                                                   !2, $14
   31    12        INIT_METHOD_CALL                                         !2, 'format'
         13        SEND_VAL_EX                                              'l'
         14        DO_FCALL                                      0  $16     
         15        ASSIGN                                                   !3, $16
   33    16        INIT_FCALL                                               'setting'
         17        CONCAT                                           ~18     'closing_time_', !3
         18        SEND_VAL                                                 ~18
         19        DO_FCALL                                      0  $19     
         20        ASSIGN                                                   !4, $19
   34    21        INIT_METHOD_CALL                                         !1, 'setTime'
         22        INIT_FCALL                                               'explode'
         23        SEND_VAL                                                 '%3A'
         24        SEND_VAR                                                 !4
         25        DO_ICALL                                         $21     
         26        SEND_UNPACK                                              $21
         27        CHECK_UNDEF_ARGS                                         
         28        DO_FCALL                                      1  $22     
         29        ASSIGN                                                   !5, $22
   36    30        INIT_METHOD_CALL                                         !5, 'format'
         31        SEND_VAL_EX                                              'a'
         32        DO_FCALL                                      0  $24     
         33        IS_IDENTICAL                                     ~25     $24, 'am'
         34      > JMPZ_EX                                          ~25     ~25, ->37
         35    >   IS_SMALLER                                       ~26     !1, !5
         36        BOOL                                             ~25     ~26
         37    > > JMPZ                                                     ~25, ->39
   38    38    >   ASSIGN                                                   !1, !2
   42    39    >   INIT_METHOD_CALL                                         !1, 'format'
         40        SEND_VAL_EX                                              'l'
         41        DO_FCALL                                      0  $28     
         42        ASSIGN                                                   !6, $28
   43    43        INIT_FCALL                                               'setting'
         44        CONCAT                                           ~30     'opening_time_', !6
         45        SEND_VAL                                                 ~30
         46        DO_FCALL                                      0  $31     
         47        ASSIGN                                                   !7, $31
   44    48        INIT_FCALL                                               'setting'
         49        CONCAT                                           ~33     'closing_time_', !6
         50        SEND_VAL                                                 ~33
         51        DO_FCALL                                      0  $34     
         52        ASSIGN                                                   !8, $34
   46    53        CONCAT                                           ~36     !6, '%3A+'
         54        CONCAT                                           ~37     ~36, !7
         55        CONCAT                                           ~38     ~37, '+-+'
         56        CONCAT                                           ~39     ~38, !8
         57      > RETURN                                                   ~39
   47    58*     > RETURN                                                   null

End of function today

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.22 ms | 1027 KiB | 20 Q