3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start_date = '2014-01-01'; $end_date = '2015-01-31'; $date_regex = "/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/"; if (!empty($start_date) & !empty($end_date) && preg_match($date_regex, $start_date) && preg_match($date_regex, $end_date)) { $start = new \DateTime($start_date); $end = new \DateTime($end_date); $now = new \DateTime(); $intervals = []; while ($start <= $end) { $first_day = $start->format('Y-m-d'); if ( $start->format('Y-m') === $now->format('Y-m') ) { $last_day = $now->format('Y-m-d'); } else { $last_day = date('Y-m-t', strtotime($start->format('Y-m'))); } $intervals[ $first_day ] = $last_day; $start->modify('first day of next month'); } echo '<pre>';print_r($intervals); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 73
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 34
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 51
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 34
Branch analysis from position: 69
Branch analysis from position: 34
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 34
Branch analysis from position: 69
Branch analysis from position: 34
Branch analysis from position: 73
Branch analysis from position: 20
Branch analysis from position: 14
filename:       /in/IeEd7
function name:  (null)
number of ops:  74
compiled vars:  !0 = $start_date, !1 = $end_date, !2 = $date_regex, !3 = $start, !4 = $end, !5 = $now, !6 = $intervals, !7 = $first_day, !8 = $last_day
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '2014-01-01'
    3     1        ASSIGN                                                   !1, '2015-01-31'
    5     2        ASSIGN                                                   !2, '%2F%5E%5B0-9%5D%7B4%7D-%280%5B1-9%5D%7C1%5B0-2%5D%29-%280%5B1-9%5D%7C%5B1-2%5D%5B0-9%5D%7C3%5B0-1%5D%29%24%2F'
    7     3        ISSET_ISEMPTY_CV                                 ~12     !0
          4        BOOL_NOT                                         ~13     ~12
          5        ISSET_ISEMPTY_CV                                 ~14     !1
          6        BOOL_NOT                                         ~15     ~14
          7        BW_AND                                           ~16     ~13, ~15
          8      > JMPZ_EX                                          ~16     ~16, ->14
          9    >   INIT_FCALL                                               'preg_match'
         10        SEND_VAR                                                 !2
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $17     
         13        BOOL                                             ~16     $17
         14    > > JMPZ_EX                                          ~16     ~16, ->20
         15    >   INIT_FCALL                                               'preg_match'
         16        SEND_VAR                                                 !2
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $18     
         19        BOOL                                             ~16     $18
         20    > > JMPZ                                                     ~16, ->73
    9    21    >   NEW                                              $19     'DateTime'
         22        SEND_VAR_EX                                              !0
         23        DO_FCALL                                      0          
         24        ASSIGN                                                   !3, $19
   10    25        NEW                                              $22     'DateTime'
         26        SEND_VAR_EX                                              !1
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !4, $22
   11    29        NEW                                              $25     'DateTime'
         30        DO_FCALL                                      0          
         31        ASSIGN                                                   !5, $25
   13    32        ASSIGN                                                   !6, <array>
   15    33      > JMP                                                      ->67
   16    34    >   INIT_METHOD_CALL                                         !3, 'format'
         35        SEND_VAL_EX                                              'Y-m-d'
         36        DO_FCALL                                      0  $29     
         37        ASSIGN                                                   !7, $29
   18    38        INIT_METHOD_CALL                                         !3, 'format'
         39        SEND_VAL_EX                                              'Y-m'
         40        DO_FCALL                                      0  $31     
         41        INIT_METHOD_CALL                                         !5, 'format'
         42        SEND_VAL_EX                                              'Y-m'
         43        DO_FCALL                                      0  $32     
         44        IS_IDENTICAL                                             $31, $32
         45      > JMPZ                                                     ~33, ->51
   19    46    >   INIT_METHOD_CALL                                         !5, 'format'
         47        SEND_VAL_EX                                              'Y-m-d'
         48        DO_FCALL                                      0  $34     
         49        ASSIGN                                                   !8, $34
         50      > JMP                                                      ->62
   21    51    >   INIT_FCALL                                               'date'
         52        SEND_VAL                                                 'Y-m-t'
         53        INIT_FCALL                                               'strtotime'
         54        INIT_METHOD_CALL                                         !3, 'format'
         55        SEND_VAL_EX                                              'Y-m'
         56        DO_FCALL                                      0  $36     
         57        SEND_VAR                                                 $36
         58        DO_ICALL                                         $37     
         59        SEND_VAR                                                 $37
         60        DO_ICALL                                         $38     
         61        ASSIGN                                                   !8, $38
   24    62    >   ASSIGN_DIM                                               !6, !7
         63        OP_DATA                                                  !8
   25    64        INIT_METHOD_CALL                                         !3, 'modify'
         65        SEND_VAL_EX                                              'first+day+of+next+month'
         66        DO_FCALL                                      0          
   15    67    >   IS_SMALLER_OR_EQUAL                                      !3, !4
         68      > JMPNZ                                                    ~42, ->34
   28    69    >   ECHO                                                     '%3Cpre%3E'
         70        INIT_FCALL                                               'print_r'
         71        SEND_VAR                                                 !6
         72        DO_ICALL                                                 
   30    73    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.78 ms | 1400 KiB | 21 Q