3v4l.org

run code in 300+ PHP versions simultaneously
<?php $result = []; $start = new \DateTime('2016-11-12'); $start->modify('monday this week'); $end = new \DateTime('2017-05-06'); $end->modify('monday next week'); $p = new \DatePeriod( $start, new \DateInterval('P1W'), $end ); foreach ($p as $d) { $y = $d->format("Y"); $m = $d->format("M"); if (!array_key_exists($y, $result['years'])){ $result['years'][$y] = ['y' => $y]; } $result['years'][$y]['months'][$d->format("m")] = ['m' => $m]; //$result[$d->format("Y")][$d->format("M")][] = [$d, (clone $d)->modify("sunday this week")]; } print_r($result); exit; foreach ($result as $year => $months){ echo $year . PHP_EOL; foreach ($months as $month => $weeks){ echo "--" . $month . PHP_EOL; foreach ($weeks as $week){ echo "----" . $week[0]->format("jM") . "-" . $week[1]->format("jM") . PHP_EOL; } } } exit; $start = new DateTime('2010-12-02'); $start->modify('first day of this month'); $end = new DateTime('2012-05-06'); $end->modify('first day of next month'); $interval = DateInterval::createFromDateString('1 month'); $period = new DatePeriod($start, $interval, $end); foreach ($period as $dt) { echo $dt->format("Y-m") . PHP_EOL; $interval_1 = DateInterval::createFromDateString('1 week'); $end_1 = clone $dt; $end_1->add($interval); $period_1 = new DatePeriod($dt, $interval_1, $end_1); foreach ($period_1 as $dt_1){ echo "--" . $dt_1->format("Y-m-d") . PHP_EOL; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 52
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 52
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 42
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 42
Branch analysis from position: 52
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 52
filename:       /in/7qpkS
function name:  (null)
number of ops:  149
compiled vars:  !0 = $result, !1 = $start, !2 = $end, !3 = $p, !4 = $d, !5 = $y, !6 = $m, !7 = $months, !8 = $year, !9 = $weeks, !10 = $month, !11 = $week, !12 = $interval, !13 = $period, !14 = $dt, !15 = $interval_1, !16 = $end_1, !17 = $period_1, !18 = $dt_1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, <array>
    7     1        NEW                                              $20     'DateTime'
          2        SEND_VAL_EX                                              '2016-11-12'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $20
    8     5        INIT_METHOD_CALL                                         !1, 'modify'
          6        SEND_VAL_EX                                              'monday+this+week'
          7        DO_FCALL                                      0          
    9     8        NEW                                              $24     'DateTime'
          9        SEND_VAL_EX                                              '2017-05-06'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $24
   10    12        INIT_METHOD_CALL                                         !2, 'modify'
         13        SEND_VAL_EX                                              'monday+next+week'
         14        DO_FCALL                                      0          
   12    15        NEW                                              $28     'DatePeriod'
   13    16        SEND_VAR_EX                                              !1
   14    17        NEW                                              $29     'DateInterval'
         18        SEND_VAL_EX                                              'P1W'
         19        DO_FCALL                                      0          
         20        SEND_VAR_NO_REF_EX                                       $29
   13    21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0          
   12    23        ASSIGN                                                   !3, $28
   18    24      > FE_RESET_R                                       $33     !3, ->52
         25    > > FE_FETCH_R                                               $33, !4, ->52
   19    26    >   INIT_METHOD_CALL                                         !4, 'format'
         27        SEND_VAL_EX                                              'Y'
         28        DO_FCALL                                      0  $34     
         29        ASSIGN                                                   !5, $34
   20    30        INIT_METHOD_CALL                                         !4, 'format'
         31        SEND_VAL_EX                                              'M'
         32        DO_FCALL                                      0  $36     
         33        ASSIGN                                                   !6, $36
   21    34        FETCH_DIM_R                                      ~38     !0, 'years'
         35        ARRAY_KEY_EXISTS                                 ~39     !5, ~38
         36        BOOL_NOT                                         ~40     ~39
         37      > JMPZ                                                     ~40, ->42
   22    38    >   INIT_ARRAY                                       ~43     !5, 'y'
         39        FETCH_DIM_W                                      $41     !0, 'years'
         40        ASSIGN_DIM                                               $41, !5
         41        OP_DATA                                                  ~43
   25    42    >   INIT_METHOD_CALL                                         !4, 'format'
         43        SEND_VAL_EX                                              'm'
         44        DO_FCALL                                      0  $47     
         45        INIT_ARRAY                                       ~49     !6, 'm'
         46        FETCH_DIM_W                                      $44     !0, 'years'
         47        FETCH_DIM_W                                      $45     $44, !5
         48        FETCH_DIM_W                                      $46     $45, 'months'
         49        ASSIGN_DIM                                               $46, $47
         50        OP_DATA                                                  ~49
   18    51      > JMP                                                      ->25
         52    >   FE_FREE                                                  $33
   30    53        INIT_FCALL                                               'print_r'
         54        SEND_VAR                                                 !0
         55        DO_ICALL                                                 
   31    56      > EXIT                                                     
   33    57*       FE_RESET_R                                       $51     !0, ->88
         58*       FE_FETCH_R                                       ~52     $51, !7, ->88
         59*       ASSIGN                                                   !8, ~52
   34    60*       CONCAT                                           ~54     !8, '%0A'
         61*       ECHO                                                     ~54
   35    62*       FE_RESET_R                                       $55     !7, ->86
         63*       FE_FETCH_R                                       ~56     $55, !9, ->86
         64*       ASSIGN                                                   !10, ~56
   36    65*       CONCAT                                           ~58     '--', !10
         66*       CONCAT                                           ~59     ~58, '%0A'
         67*       ECHO                                                     ~59
   37    68*       FE_RESET_R                                       $60     !9, ->84
         69*       FE_FETCH_R                                               $60, !11, ->84
   38    70*       FETCH_DIM_R                                      ~61     !11, 0
         71*       INIT_METHOD_CALL                                         ~61, 'format'
         72*       SEND_VAL_EX                                              'jM'
         73*       DO_FCALL                                      0  $62     
         74*       CONCAT                                           ~63     '----', $62
         75*       CONCAT                                           ~64     ~63, '-'
         76*       FETCH_DIM_R                                      ~65     !11, 1
         77*       INIT_METHOD_CALL                                         ~65, 'format'
         78*       SEND_VAL_EX                                              'jM'
         79*       DO_FCALL                                      0  $66     
         80*       CONCAT                                           ~67     ~64, $66
         81*       CONCAT                                           ~68     ~67, '%0A'
         82*       ECHO                                                     ~68
   37    83*       JMP                                                      ->69
         84*       FE_FREE                                                  $60
   35    85*       JMP                                                      ->63
         86*       FE_FREE                                                  $55
   33    87*       JMP                                                      ->58
         88*       FE_FREE                                                  $51
   47    89*       EXIT                                                     
   48    90*       NEW                                              $69     'DateTime'
         91*       SEND_VAL_EX                                              '2010-12-02'
         92*       DO_FCALL                                      0          
         93*       ASSIGN                                                   !1, $69
   49    94*       INIT_METHOD_CALL                                         !1, 'modify'
         95*       SEND_VAL_EX                                              'first+day+of+this+month'
         96*       DO_FCALL                                      0          
   50    97*       NEW                                              $73     'DateTime'
         98*       SEND_VAL_EX                                              '2012-05-06'
         99*       DO_FCALL                                      0          
        100*       ASSIGN                                                   !2, $73
   51   101*       INIT_METHOD_CALL                                         !2, 'modify'
        102*       SEND_VAL_EX                                              'first+day+of+next+month'
        103*       DO_FCALL                                      0          
   52   104*       INIT_STATIC_METHOD_CALL                                  'DateInterval', 'createFromDateString'
        105*       SEND_VAL                                                 '1+month'
        106*       DO_FCALL                                      0  $77     
        107*       ASSIGN                                                   !12, $77
   53   108*       NEW                                              $79     'DatePeriod'
        109*       SEND_VAR_EX                                              !1
        110*       SEND_VAR_EX                                              !12
        111*       SEND_VAR_EX                                              !2
        112*       DO_FCALL                                      0          
        113*       ASSIGN                                                   !13, $79
   56   114*       FE_RESET_R                                       $82     !13, ->147
        115*       FE_FETCH_R                                               $82, !14, ->147
   57   116*       INIT_METHOD_CALL                                         !14, 'format'
        117*       SEND_VAL_EX                                              'Y-m'
        118*       DO_FCALL                                      0  $83     
        119*       CONCAT                                           ~84     $83, '%0A'
        120*       ECHO                                                     ~84
   58   121*       INIT_STATIC_METHOD_CALL                                  'DateInterval', 'createFromDateString'
        122*       SEND_VAL                                                 '1+week'
        123*       DO_FCALL                                      0  $85     
        124*       ASSIGN                                                   !15, $85
   59   125*       CLONE                                            ~87     !14
        126*       ASSIGN                                                   !16, ~87
   60   127*       INIT_METHOD_CALL                                         !16, 'add'
        128*       SEND_VAR_EX                                              !12
        129*       DO_FCALL                                      0          
   61   130*       NEW                                              $90     'DatePeriod'
        131*       SEND_VAR_EX                                              !14
        132*       SEND_VAR_EX                                              !15
        133*       SEND_VAR_EX                                              !16
        134*       DO_FCALL                                      0          
        135*       ASSIGN                                                   !17, $90
   63   136*       FE_RESET_R                                       $93     !17, ->145
        137*       FE_FETCH_R                                               $93, !18, ->145
   64   138*       INIT_METHOD_CALL                                         !18, 'format'
        139*       SEND_VAL_EX                                              'Y-m-d'
        140*       DO_FCALL                                      0  $94     
        141*       CONCAT                                           ~95     '--', $94
        142*       CONCAT                                           ~96     ~95, '%0A'
        143*       ECHO                                                     ~96
   63   144*       JMP                                                      ->137
        145*       FE_FREE                                                  $93
   56   146*       JMP                                                      ->115
        147*       FE_FREE                                                  $82
   67   148*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
278.25 ms | 1412 KiB | 16 Q