3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getItem($date, $startDate, $skipped_days){ $item = array('a','b','c','b','c'); $diff = date_create($startDate)->diff(date_create($date)); if($diff->invert) return false; //error $date < $startDate return $item[($diff->days - $skipped_days) % 5]; } //example for use $startDate = '2019-10-01'; $skipday = '2019-10-07'; $skipped_days = 0; $selected_start_date = '2019-10-01'; $selected_end_date = '2019-10-10'; $dates_array = array(); $current_date = strtotime($selected_start_date); $last_date = strtotime($selected_end_date); while( $current_date <= $last_date ) { $dates_array[] = date('Y-m-d', $current_date); $current_date = strtotime('+1 day', $current_date); } for($i=0; $i<count($dates_array); $i++) { $today = $dates_array[$i]; $code = getItem($today, $startDate, $skipped_days); if($dates_array[$i] == $skipday) { $code = "SKIP"; $skipped_days++; } echo $today." ".$code."</br>\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 15
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 30
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 30
Branch analysis from position: 51
Branch analysis from position: 30
Branch analysis from position: 43
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 15
Branch analysis from position: 28
Branch analysis from position: 15
filename:       /in/CK3f3
function name:  (null)
number of ops:  52
compiled vars:  !0 = $startDate, !1 = $skipday, !2 = $skipped_days, !3 = $selected_start_date, !4 = $selected_end_date, !5 = $dates_array, !6 = $current_date, !7 = $last_date, !8 = $i, !9 = $today, !10 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, '2019-10-01'
   12     1        ASSIGN                                                   !1, '2019-10-07'
   13     2        ASSIGN                                                   !2, 0
   15     3        ASSIGN                                                   !3, '2019-10-01'
   16     4        ASSIGN                                                   !4, '2019-10-10'
   18     5        ASSIGN                                                   !5, <array>
   19     6        INIT_FCALL                                               'strtotime'
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $17     
          9        ASSIGN                                                   !6, $17
   20    10        INIT_FCALL                                               'strtotime'
         11        SEND_VAR                                                 !4
         12        DO_ICALL                                         $19     
         13        ASSIGN                                                   !7, $19
   22    14      > JMP                                                      ->26
   23    15    >   INIT_FCALL                                               'date'
         16        SEND_VAL                                                 'Y-m-d'
         17        SEND_VAR                                                 !6
         18        DO_ICALL                                         $22     
         19        ASSIGN_DIM                                               !5
         20        OP_DATA                                                  $22
   24    21        INIT_FCALL                                               'strtotime'
         22        SEND_VAL                                                 '%2B1+day'
         23        SEND_VAR                                                 !6
         24        DO_ICALL                                         $23     
         25        ASSIGN                                                   !6, $23
   22    26    >   IS_SMALLER_OR_EQUAL                                      !6, !7
         27      > JMPNZ                                                    ~25, ->15
   27    28    >   ASSIGN                                                   !8, 0
         29      > JMP                                                      ->48
   28    30    >   FETCH_DIM_R                                      ~27     !5, !8
         31        ASSIGN                                                   !9, ~27
   29    32        INIT_FCALL                                               'getitem'
         33        SEND_VAR                                                 !9
         34        SEND_VAR                                                 !0
         35        SEND_VAR                                                 !2
         36        DO_FCALL                                      0  $29     
         37        ASSIGN                                                   !10, $29
   31    38        FETCH_DIM_R                                      ~31     !5, !8
         39        IS_EQUAL                                                 !1, ~31
         40      > JMPZ                                                     ~32, ->43
   32    41    >   ASSIGN                                                   !10, 'SKIP'
   33    42        PRE_INC                                                  !2
   36    43    >   CONCAT                                           ~35     !9, '+'
         44        CONCAT                                           ~36     ~35, !10
         45        CONCAT                                           ~37     ~36, '%3C%2Fbr%3E%0A'
         46        ECHO                                                     ~37
   27    47        PRE_INC                                                  !8
         48    >   COUNT                                            ~39     !5
         49        IS_SMALLER                                               !8, ~39
         50      > JMPNZ                                                    ~40, ->30
   38    51    > > RETURN                                                   1

Function getitem:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CK3f3
function name:  getItem
number of ops:  23
compiled vars:  !0 = $date, !1 = $startDate, !2 = $skipped_days, !3 = $item, !4 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    4     3        ASSIGN                                                   !3, <array>
    5     4        INIT_FCALL                                               'date_create'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $6      
          7        INIT_METHOD_CALL                                         $6, 'diff'
          8        INIT_FCALL                                               'date_create'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $7      
         11        SEND_VAR_NO_REF_EX                                       $7
         12        DO_FCALL                                      0  $8      
         13        ASSIGN                                                   !4, $8
    6    14        FETCH_OBJ_R                                      ~10     !4, 'invert'
         15      > JMPZ                                                     ~10, ->17
         16    > > RETURN                                                   <false>
    7    17    >   FETCH_OBJ_R                                      ~11     !4, 'days'
         18        SUB                                              ~12     ~11, !2
         19        MOD                                              ~13     ~12, 5
         20        FETCH_DIM_R                                      ~14     !3, ~13
         21      > RETURN                                                   ~14
    8    22*     > RETURN                                                   null

End of function getitem

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.74 ms | 1013 KiB | 17 Q