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) { $currentDate = new \DateTimeImmutable($dateString); if (in_array($currentDate->format('N'), [2, 3, 4, 5])) { //check current time is not beyond the threshold //Monday = 1 and Sunday = 7 | Thursday = 4 $closedDate = $currentDate->setTime(1, 30, 00); if ($currentDate < $closedDate) { //change the date to display to day prior $currentDate = $currentDate->sub(new \DateInterval('P1D')); } } $today = $currentDate->format('l'); $start = setting('opening_time_' . $today); // Select value from settings table $end = setting('closing_time_' . $today); // Select value from settings table 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/Vtr6L
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
-------------------------------------------------------------------------------------
   46     0  E >   ASSIGN                                                   !0, <array>
   47     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->43
   48     3    >   INIT_FCALL                                               'date_create'
          4        SEND_VAL                                                 '2018-10-08'
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !2, $7
   49     7        IS_SMALLER                                               0, !1
          8      > JMPZ                                                     ~9, ->14
   50     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          
   52    14    >   INIT_METHOD_CALL                                         !2, 'format'
         15        SEND_VAL_EX                                              'l'
         16        DO_FCALL                                      0  $13     
   53    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'
   54    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'
   52    40        ASSIGN_DIM                                               !0, $13
   54    41        OP_DATA                                                  ~18
   47    42        PRE_INC                                                  !1
         43    >   IS_SMALLER                                               !1, 7
         44      > JMPNZ                                                    ~23, ->3
   57    45    >   ECHO                                                     'Day+++++++++%09%7C%0900%3A15%3A00%09%09%09%7C%0923%3A00%3A00%0A'
   58    46      > FE_RESET_R                                       $24     !0, ->59
         47    > > FE_FETCH_R                                       ~25     $24, !3, ->59
         48    >   ASSIGN                                                   !4, ~25
   59    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
   58    58      > JMP                                                      ->47
         59    >   FE_FREE                                                  $24
   60    60      > RETURN                                                   1

Function setting:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vtr6L
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 = 43) Position 1 = 13, Position 2 = 28
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 28
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 28
filename:       /in/Vtr6L
function name:  Today
number of ops:  48
compiled vars:  !0 = $dateString, !1 = $currentDate, !2 = $closedDate, !3 = $today, !4 = $start, !5 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        NEW                                              $6      'DateTimeImmutable'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $6
   29     5        INIT_FCALL                                               'in_array'
          6        INIT_METHOD_CALL                                         !1, 'format'
          7        SEND_VAL_EX                                              'N'
          8        DO_FCALL                                      0  $9      
          9        SEND_VAR                                                 $9
         10        SEND_VAL                                                 <array>
         11        DO_ICALL                                         $10     
         12      > JMPZ                                                     $10, ->28
   32    13    >   INIT_METHOD_CALL                                         !1, 'setTime'
         14        SEND_VAL_EX                                              1
         15        SEND_VAL_EX                                              30
         16        SEND_VAL_EX                                              0
         17        DO_FCALL                                      0  $11     
         18        ASSIGN                                                   !2, $11
   33    19        IS_SMALLER                                               !1, !2
         20      > JMPZ                                                     ~13, ->28
   35    21    >   INIT_METHOD_CALL                                         !1, 'sub'
         22        NEW                                              $14     'DateInterval'
         23        SEND_VAL_EX                                              'P1D'
         24        DO_FCALL                                      0          
         25        SEND_VAR_NO_REF_EX                                       $14
         26        DO_FCALL                                      0  $16     
         27        ASSIGN                                                   !1, $16
   38    28    >   INIT_METHOD_CALL                                         !1, 'format'
         29        SEND_VAL_EX                                              'l'
         30        DO_FCALL                                      0  $18     
         31        ASSIGN                                                   !3, $18
   40    32        INIT_FCALL                                               'setting'
         33        CONCAT                                           ~20     'opening_time_', !3
         34        SEND_VAL                                                 ~20
         35        DO_FCALL                                      0  $21     
         36        ASSIGN                                                   !4, $21
   41    37        INIT_FCALL                                               'setting'
         38        CONCAT                                           ~23     'closing_time_', !3
         39        SEND_VAL                                                 ~23
         40        DO_FCALL                                      0  $24     
         41        ASSIGN                                                   !5, $24
   42    42        CONCAT                                           ~26     !3, '%3A+'
         43        CONCAT                                           ~27     ~26, !4
         44        CONCAT                                           ~28     ~27, '+-+'
         45        CONCAT                                           ~29     ~28, !5
         46      > RETURN                                                   ~29
   43    47*     > RETURN                                                   null

End of function today

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.69 ms | 1449 KiB | 19 Q