3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Date intervals gaps // date intervals as input (add as many as needed) $dates = array( array('01-01-2001', '31-01-2001'), array('10-02-2001', '20-02-2001'), array('31-12-2000', '30-03-2001') ); // end of input area if (!count($dates)) { echo 'No date intervals were given! <br />'; return; } $input_errors = 0; $intervals = array(); // build $intervals array with valid dates from input foreach ($dates as $i => $date) { if (!strtotime($date[0]) || !strtotime($date[1])) { $input_errors++; echo "Input error for $date[0] - $date[1] (#$i date interval). <br />"; continue; } $intervals[] = array( 'start' => date('d-m-Y', strtotime($date[0])), 'end' => date('d-m-Y', strtotime($date[1])) ); } if ($input_errors) { echo 'The given date intervals contain input error(s), as listed above, thus date gaps verification can not be performed. <br />'; echo 'For a retry, please correct the input date intervals or set a date after 1970 and before 2038. <br />'; return; } // sort $intervals array by start date of each interval $sorted = usort($intervals, "sortByStartDate"); if (!$sorted) { echo 'Error sorting intervals by start date. Exiting... <br />'; return; } print_r($sorted); // $start is the smallest start date of all intervals $start = $intervals[0]['start']; // $end is the biggest end date of all intervals $end = $intervals[0]['end']; $prev_end = $intervals[0]['end']; $total = count($intervals); $gaps = array(); if ($total == 1) { echo 'Only one date interval given, thus no gaps exist. <br />'; return; } // starting from the 2nd interval, check for gaps between $start and $end for ($j = 1; $j < $total; $j++) { if ($start > $intervals[$j]['start']) { $start = $intervals[$j]['start']; } if ((strtotime($intervals[$j]['start']) > strtotime($prev_end)) && (strtotime($end) < strtotime($intervals[$j]['start']))) { $gaps[] = array( 'start' => $prev_end, 'end' => $intervals[$j]['start'] ); } $prev_end = $intervals[$j]['end']; if ($end < $intervals[$j]['end']) { $end = $intervals[$j]['end']; } } echo "The smallest start date of all intervals is $start. <br .>"; echo "The biggest end date of all intervals is $end. <br />"; if (!count($gaps)) { echo 'The given date intervals do not contain gaps. <br />'; } else { echo 'The given date intervals contains the fallowing gaps: <br />'; foreach ($gaps as $gap) { echo '[ '. $gap['start'] . ' , ' . $gap['end'] . ' ] <br />'; } } // function used for sorting the $intervals array function sortByStartDate($a, $b) { if ($a['start'] == $b['start']) { return 0; } return ($a['start'] < $b['start']) ? -1 : 1; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 57
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 57
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 36
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 23
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 62
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 71
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 90
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 137
Branch analysis from position: 137
2 jumps found. (Code = 44) Position 1 = 139, Position 2 = 92
Branch analysis from position: 139
2 jumps found. (Code = 43) Position 1 = 150, Position 2 = 152
Branch analysis from position: 150
1 jumps found. (Code = 42) Position 1 = 164
Branch analysis from position: 164
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 152
2 jumps found. (Code = 77) Position 1 = 154, Position 2 = 163
Branch analysis from position: 154
2 jumps found. (Code = 78) Position 1 = 155, Position 2 = 163
Branch analysis from position: 155
1 jumps found. (Code = 42) Position 1 = 154
Branch analysis from position: 154
Branch analysis from position: 163
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 163
Branch analysis from position: 92
2 jumps found. (Code = 43) Position 1 = 96, Position 2 = 99
Branch analysis from position: 96
2 jumps found. (Code = 46) Position 1 = 109, Position 2 = 119
Branch analysis from position: 109
2 jumps found. (Code = 43) Position 1 = 120, Position 2 = 126
Branch analysis from position: 120
2 jumps found. (Code = 43) Position 1 = 133, Position 2 = 136
Branch analysis from position: 133
2 jumps found. (Code = 44) Position 1 = 139, Position 2 = 92
Branch analysis from position: 139
Branch analysis from position: 92
Branch analysis from position: 136
Branch analysis from position: 126
Branch analysis from position: 119
Branch analysis from position: 99
Branch analysis from position: 57
filename:       /in/3McLE
function name:  (null)
number of ops:  165
compiled vars:  !0 = $dates, !1 = $input_errors, !2 = $intervals, !3 = $date, !4 = $i, !5 = $sorted, !6 = $start, !7 = $end, !8 = $prev_end, !9 = $total, !10 = $gaps, !11 = $j, !12 = $gap
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, <array>
   23     1        COUNT                                            ~14     !0
          2        BOOL_NOT                                         ~15     ~14
          3      > JMPZ                                                     ~15, ->6
   25     4    >   ECHO                                                     'No+date+intervals+were+given%21+%3Cbr+%2F%3E'
   27     5      > RETURN                                                   null
   33     6    >   ASSIGN                                                   !1, 0
   35     7        ASSIGN                                                   !2, <array>
   41     8      > FE_RESET_R                                       $18     !0, ->57
          9    > > FE_FETCH_R                                       ~19     $18, !3, ->57
         10    >   ASSIGN                                                   !4, ~19
   43    11        INIT_FCALL                                               'strtotime'
         12        FETCH_DIM_R                                      ~21     !3, 0
         13        SEND_VAL                                                 ~21
         14        DO_ICALL                                         $22     
         15        BOOL_NOT                                         ~23     $22
         16      > JMPNZ_EX                                         ~23     ~23, ->23
         17    >   INIT_FCALL                                               'strtotime'
         18        FETCH_DIM_R                                      ~24     !3, 1
         19        SEND_VAL                                                 ~24
         20        DO_ICALL                                         $25     
         21        BOOL_NOT                                         ~26     $25
         22        BOOL                                             ~23     ~26
         23    > > JMPZ                                                     ~23, ->36
   45    24    >   PRE_INC                                                  !1
   47    25        ROPE_INIT                                     7  ~31     'Input+error+for+'
         26        FETCH_DIM_R                                      ~28     !3, 0
         27        ROPE_ADD                                      1  ~31     ~31, ~28
         28        ROPE_ADD                                      2  ~31     ~31, '+-+'
         29        FETCH_DIM_R                                      ~29     !3, 1
         30        ROPE_ADD                                      3  ~31     ~31, ~29
         31        ROPE_ADD                                      4  ~31     ~31, '+%28%23'
         32        ROPE_ADD                                      5  ~31     ~31, !4
         33        ROPE_END                                      6  ~30     ~31, '+date+interval%29.+%3Cbr+%2F%3E'
         34        ECHO                                                     ~30
   49    35      > JMP                                                      ->9
   55    36    >   INIT_FCALL                                               'date'
         37        SEND_VAL                                                 'd-m-Y'
         38        INIT_FCALL                                               'strtotime'
         39        FETCH_DIM_R                                      ~36     !3, 0
         40        SEND_VAL                                                 ~36
         41        DO_ICALL                                         $37     
         42        SEND_VAR                                                 $37
         43        DO_ICALL                                         $38     
         44        INIT_ARRAY                                       ~39     $38, 'start'
   57    45        INIT_FCALL                                               'date'
         46        SEND_VAL                                                 'd-m-Y'
         47        INIT_FCALL                                               'strtotime'
         48        FETCH_DIM_R                                      ~40     !3, 1
         49        SEND_VAL                                                 ~40
         50        DO_ICALL                                         $41     
         51        SEND_VAR                                                 $41
         52        DO_ICALL                                         $42     
         53        ADD_ARRAY_ELEMENT                                ~39     $42, 'end'
   53    54        ASSIGN_DIM                                               !2
   57    55        OP_DATA                                                  ~39
   41    56      > JMP                                                      ->9
         57    >   FE_FREE                                                  $18
   65    58      > JMPZ                                                     !1, ->62
   67    59    >   ECHO                                                     'The+given+date+intervals+contain+input+error%28s%29%2C+as+listed+above%2C+thus+date+gaps+verification+can+not+be+performed.+%3Cbr+%2F%3E'
   69    60        ECHO                                                     'For+a+retry%2C+please+correct+the+input+date+intervals+or+set+a+date+after+1970+and+before+2038.+%3Cbr+%2F%3E'
   71    61      > RETURN                                                   null
   79    62    >   INIT_FCALL                                               'usort'
         63        SEND_REF                                                 !2
         64        SEND_VAL                                                 'sortByStartDate'
         65        DO_ICALL                                         $43     
         66        ASSIGN                                                   !5, $43
   83    67        BOOL_NOT                                         ~45     !5
         68      > JMPZ                                                     ~45, ->71
   85    69    >   ECHO                                                     'Error+sorting+intervals+by+start+date.+Exiting...+%3Cbr+%2F%3E'
   87    70      > RETURN                                                   null
   91    71    >   INIT_FCALL                                               'print_r'
         72        SEND_VAR                                                 !5
         73        DO_ICALL                                                 
   96    74        FETCH_DIM_R                                      ~47     !2, 0
         75        FETCH_DIM_R                                      ~48     ~47, 'start'
         76        ASSIGN                                                   !6, ~48
  100    77        FETCH_DIM_R                                      ~50     !2, 0
         78        FETCH_DIM_R                                      ~51     ~50, 'end'
         79        ASSIGN                                                   !7, ~51
  102    80        FETCH_DIM_R                                      ~53     !2, 0
         81        FETCH_DIM_R                                      ~54     ~53, 'end'
         82        ASSIGN                                                   !8, ~54
  104    83        COUNT                                            ~56     !2
         84        ASSIGN                                                   !9, ~56
  106    85        ASSIGN                                                   !10, <array>
  110    86        IS_EQUAL                                                 !9, 1
         87      > JMPZ                                                     ~59, ->90
  112    88    >   ECHO                                                     'Only+one+date+interval+given%2C+thus+no+gaps+exist.+%3Cbr+%2F%3E'
  114    89      > RETURN                                                   null
  122    90    >   ASSIGN                                                   !11, 1
         91      > JMP                                                      ->137
  124    92    >   FETCH_DIM_R                                      ~61     !2, !11
         93        FETCH_DIM_R                                      ~62     ~61, 'start'
         94        IS_SMALLER                                               ~62, !6
         95      > JMPZ                                                     ~63, ->99
  126    96    >   FETCH_DIM_R                                      ~64     !2, !11
         97        FETCH_DIM_R                                      ~65     ~64, 'start'
         98        ASSIGN                                                   !6, ~65
  132    99    >   INIT_FCALL                                               'strtotime'
        100        FETCH_DIM_R                                      ~67     !2, !11
        101        FETCH_DIM_R                                      ~68     ~67, 'start'
        102        SEND_VAL                                                 ~68
        103        DO_ICALL                                         $69     
        104        INIT_FCALL                                               'strtotime'
        105        SEND_VAR                                                 !8
        106        DO_ICALL                                         $70     
        107        IS_SMALLER                                       ~71     $70, $69
        108      > JMPZ_EX                                          ~71     ~71, ->119
        109    >   INIT_FCALL                                               'strtotime'
        110        SEND_VAR                                                 !7
        111        DO_ICALL                                         $72     
        112        INIT_FCALL                                               'strtotime'
        113        FETCH_DIM_R                                      ~73     !2, !11
        114        FETCH_DIM_R                                      ~74     ~73, 'start'
        115        SEND_VAL                                                 ~74
        116        DO_ICALL                                         $75     
        117        IS_SMALLER                                       ~76     $72, $75
        118        BOOL                                             ~71     ~76
        119    > > JMPZ                                                     ~71, ->126
  136   120    >   INIT_ARRAY                                       ~78     !8, 'start'
  138   121        FETCH_DIM_R                                      ~79     !2, !11
        122        FETCH_DIM_R                                      ~80     ~79, 'start'
        123        ADD_ARRAY_ELEMENT                                ~78     ~80, 'end'
  134   124        ASSIGN_DIM                                               !10
  138   125        OP_DATA                                                  ~78
  146   126    >   FETCH_DIM_R                                      ~81     !2, !11
        127        FETCH_DIM_R                                      ~82     ~81, 'end'
        128        ASSIGN                                                   !8, ~82
  150   129        FETCH_DIM_R                                      ~84     !2, !11
        130        FETCH_DIM_R                                      ~85     ~84, 'end'
        131        IS_SMALLER                                               !7, ~85
        132      > JMPZ                                                     ~86, ->136
  152   133    >   FETCH_DIM_R                                      ~87     !2, !11
        134        FETCH_DIM_R                                      ~88     ~87, 'end'
        135        ASSIGN                                                   !7, ~88
  122   136    >   PRE_INC                                                  !11
        137    >   IS_SMALLER                                               !11, !9
        138      > JMPNZ                                                    ~91, ->92
  160   139    >   ROPE_INIT                                     3  ~93     'The+smallest+start+date+of+all+intervals+is+'
        140        ROPE_ADD                                      1  ~93     ~93, !6
        141        ROPE_END                                      2  ~92     ~93, '.+%3Cbr+.%3E'
        142        ECHO                                                     ~92
  162   143        ROPE_INIT                                     3  ~96     'The+biggest+end+date+of+all+intervals+is+'
        144        ROPE_ADD                                      1  ~96     ~96, !7
        145        ROPE_END                                      2  ~95     ~96, '.+%3Cbr+%2F%3E'
        146        ECHO                                                     ~95
  166   147        COUNT                                            ~98     !10
        148        BOOL_NOT                                         ~99     ~98
        149      > JMPZ                                                     ~99, ->152
  168   150    >   ECHO                                                     'The+given+date+intervals+do+not+contain+gaps.+%3Cbr+%2F%3E'
        151      > JMP                                                      ->164
  172   152    >   ECHO                                                     'The+given+date+intervals+contains+the+fallowing+gaps%3A+%3Cbr+%2F%3E'
  174   153      > FE_RESET_R                                       $100    !10, ->163
        154    > > FE_FETCH_R                                               $100, !12, ->163
  176   155    >   FETCH_DIM_R                                      ~101    !12, 'start'
        156        CONCAT                                           ~102    '%5B+', ~101
        157        CONCAT                                           ~103    ~102, '+%2C+'
        158        FETCH_DIM_R                                      ~104    !12, 'end'
        159        CONCAT                                           ~105    ~103, ~104
        160        CONCAT                                           ~106    ~105, '+%5D+%3Cbr+%2F%3E'
        161        ECHO                                                     ~106
  174   162      > JMP                                                      ->154
        163    >   FE_FREE                                                  $100
  200   164    > > RETURN                                                   1

Function sortbystartdate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3McLE
function name:  sortByStartDate
number of ops:  16
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  186     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  190     2        FETCH_DIM_R                                      ~2      !0, 'start'
          3        FETCH_DIM_R                                      ~3      !1, 'start'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
  192     6    > > RETURN                                                   0
  198     7    >   FETCH_DIM_R                                      ~5      !0, 'start'
          8        FETCH_DIM_R                                      ~6      !1, 'start'
          9        IS_SMALLER                                               ~5, ~6
         10      > JMPZ                                                     ~7, ->13
         11    >   QM_ASSIGN                                        ~8      -1
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~8      1
         14    > > RETURN                                                   ~8
  200    15*     > RETURN                                                   null

End of function sortbystartdate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.13 ms | 1412 KiB | 21 Q