3v4l.org

run code in 300+ PHP versions simultaneously
<?php $result['years'] = []; $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]; } if (!arrray_key_exists($d->format("m"), $result['years'][$y]['months'])){ $result['years'][$y]['months'][$d->format("m")] = ['m' => $m]; } $result['years'][$y]['months'][$m]['weeks'][] = ['f' => $d, 't' => (clone $d)->modify("sunday this week")]; //$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 = 26, Position 2 = 79
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 79
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 65
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 65
Branch analysis from position: 43
Branch analysis from position: 79
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 79
filename:       /in/L4jQi
function name:  (null)
number of ops:  176
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_DIM                                               !0, 'years'
          1        OP_DATA                                                  <array>
    7     2        NEW                                              $20     'DateTime'
          3        SEND_VAL_EX                                              '2016-11-12'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $20
    8     6        INIT_METHOD_CALL                                         !1, 'modify'
          7        SEND_VAL_EX                                              'monday+this+week'
          8        DO_FCALL                                      0          
    9     9        NEW                                              $24     'DateTime'
         10        SEND_VAL_EX                                              '2017-05-06'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $24
   10    13        INIT_METHOD_CALL                                         !2, 'modify'
         14        SEND_VAL_EX                                              'monday+next+week'
         15        DO_FCALL                                      0          
   12    16        NEW                                              $28     'DatePeriod'
   13    17        SEND_VAR_EX                                              !1
   14    18        NEW                                              $29     'DateInterval'
         19        SEND_VAL_EX                                              'P1W'
         20        DO_FCALL                                      0          
         21        SEND_VAR_NO_REF_EX                                       $29
   13    22        SEND_VAR_EX                                              !2
         23        DO_FCALL                                      0          
   12    24        ASSIGN                                                   !3, $28
   18    25      > FE_RESET_R                                       $33     !3, ->79
         26    > > FE_FETCH_R                                               $33, !4, ->79
   19    27    >   INIT_METHOD_CALL                                         !4, 'format'
         28        SEND_VAL_EX                                              'Y'
         29        DO_FCALL                                      0  $34     
         30        ASSIGN                                                   !5, $34
   20    31        INIT_METHOD_CALL                                         !4, 'format'
         32        SEND_VAL_EX                                              'M'
         33        DO_FCALL                                      0  $36     
         34        ASSIGN                                                   !6, $36
   21    35        FETCH_DIM_R                                      ~38     !0, 'years'
         36        ARRAY_KEY_EXISTS                                 ~39     !5, ~38
         37        BOOL_NOT                                         ~40     ~39
         38      > JMPZ                                                     ~40, ->43
   22    39    >   INIT_ARRAY                                       ~43     !5, 'y'
         40        FETCH_DIM_W                                      $41     !0, 'years'
         41        ASSIGN_DIM                                               $41, !5
         42        OP_DATA                                                  ~43
   24    43    >   INIT_FCALL_BY_NAME                                       'arrray_key_exists'
         44        INIT_METHOD_CALL                                         !4, 'format'
         45        SEND_VAL_EX                                              'm'
         46        DO_FCALL                                      0  $44     
         47        SEND_VAR_NO_REF_EX                                       $44
         48        CHECK_FUNC_ARG                                           
         49        FETCH_DIM_FUNC_ARG                               $45     !0, 'years'
         50        FETCH_DIM_FUNC_ARG                               $46     $45, !5
         51        FETCH_DIM_FUNC_ARG                               $47     $46, 'months'
         52        SEND_FUNC_ARG                                            $47
         53        DO_FCALL                                      0  $48     
         54        BOOL_NOT                                         ~49     $48
         55      > JMPZ                                                     ~49, ->65
   25    56    >   INIT_METHOD_CALL                                         !4, 'format'
         57        SEND_VAL_EX                                              'm'
         58        DO_FCALL                                      0  $53     
         59        INIT_ARRAY                                       ~55     !6, 'm'
         60        FETCH_DIM_W                                      $50     !0, 'years'
         61        FETCH_DIM_W                                      $51     $50, !5
         62        FETCH_DIM_W                                      $52     $51, 'months'
         63        ASSIGN_DIM                                               $52, $53
         64        OP_DATA                                                  ~55
   27    65    >   INIT_ARRAY                                       ~62     !4, 'f'
         66        CLONE                                            ~63     !4
         67        INIT_METHOD_CALL                                         ~63, 'modify'
         68        SEND_VAL_EX                                              'sunday+this+week'
         69        DO_FCALL                                      0  $64     
         70        ADD_ARRAY_ELEMENT                                ~62     $64, 't'
         71        FETCH_DIM_W                                      $56     !0, 'years'
         72        FETCH_DIM_W                                      $57     $56, !5
         73        FETCH_DIM_W                                      $58     $57, 'months'
         74        FETCH_DIM_W                                      $59     $58, !6
         75        FETCH_DIM_W                                      $60     $59, 'weeks'
         76        ASSIGN_DIM                                               $60
         77        OP_DATA                                                  ~62
   18    78      > JMP                                                      ->26
         79    >   FE_FREE                                                  $33
   32    80        INIT_FCALL                                               'print_r'
         81        SEND_VAR                                                 !0
         82        DO_ICALL                                                 
   33    83      > EXIT                                                     
   35    84*       FE_RESET_R                                       $66     !0, ->115
         85*       FE_FETCH_R                                       ~67     $66, !7, ->115
         86*       ASSIGN                                                   !8, ~67
   36    87*       CONCAT                                           ~69     !8, '%0A'
         88*       ECHO                                                     ~69
   37    89*       FE_RESET_R                                       $70     !7, ->113
         90*       FE_FETCH_R                                       ~71     $70, !9, ->113
         91*       ASSIGN                                                   !10, ~71
   38    92*       CONCAT                                           ~73     '--', !10
         93*       CONCAT                                           ~74     ~73, '%0A'
         94*       ECHO                                                     ~74
   39    95*       FE_RESET_R                                       $75     !9, ->111
         96*       FE_FETCH_R                                               $75, !11, ->111
   40    97*       FETCH_DIM_R                                      ~76     !11, 0
         98*       INIT_METHOD_CALL                                         ~76, 'format'
         99*       SEND_VAL_EX                                              'jM'
        100*       DO_FCALL                                      0  $77     
        101*       CONCAT                                           ~78     '----', $77
        102*       CONCAT                                           ~79     ~78, '-'
        103*       FETCH_DIM_R                                      ~80     !11, 1
        104*       INIT_METHOD_CALL                                         ~80, 'format'
        105*       SEND_VAL_EX                                              'jM'
        106*       DO_FCALL                                      0  $81     
        107*       CONCAT                                           ~82     ~79, $81
        108*       CONCAT                                           ~83     ~82, '%0A'
        109*       ECHO                                                     ~83
   39   110*       JMP                                                      ->96
        111*       FE_FREE                                                  $75
   37   112*       JMP                                                      ->90
        113*       FE_FREE                                                  $70
   35   114*       JMP                                                      ->85
        115*       FE_FREE                                                  $66
   49   116*       EXIT                                                     
   50   117*       NEW                                              $84     'DateTime'
        118*       SEND_VAL_EX                                              '2010-12-02'
        119*       DO_FCALL                                      0          
        120*       ASSIGN                                                   !1, $84
   51   121*       INIT_METHOD_CALL                                         !1, 'modify'
        122*       SEND_VAL_EX                                              'first+day+of+this+month'
        123*       DO_FCALL                                      0          
   52   124*       NEW                                              $88     'DateTime'
        125*       SEND_VAL_EX                                              '2012-05-06'
        126*       DO_FCALL                                      0          
        127*       ASSIGN                                                   !2, $88
   53   128*       INIT_METHOD_CALL                                         !2, 'modify'
        129*       SEND_VAL_EX                                              'first+day+of+next+month'
        130*       DO_FCALL                                      0          
   54   131*       INIT_STATIC_METHOD_CALL                                  'DateInterval', 'createFromDateString'
        132*       SEND_VAL                                                 '1+month'
        133*       DO_FCALL                                      0  $92     
        134*       ASSIGN                                                   !12, $92
   55   135*       NEW                                              $94     'DatePeriod'
        136*       SEND_VAR_EX                                              !1
        137*       SEND_VAR_EX                                              !12
        138*       SEND_VAR_EX                                              !2
        139*       DO_FCALL                                      0          
        140*       ASSIGN                                                   !13, $94
   58   141*       FE_RESET_R                                       $97     !13, ->174
        142*       FE_FETCH_R                                               $97, !14, ->174
   59   143*       INIT_METHOD_CALL                                         !14, 'format'
        144*       SEND_VAL_EX                                              'Y-m'
        145*       DO_FCALL                                      0  $98     
        146*       CONCAT                                           ~99     $98, '%0A'
        147*       ECHO                                                     ~99
   60   148*       INIT_STATIC_METHOD_CALL                                  'DateInterval', 'createFromDateString'
        149*       SEND_VAL                                                 '1+week'
        150*       DO_FCALL                                      0  $100    
        151*       ASSIGN                                                   !15, $100
   61   152*       CLONE                                            ~102    !14
        153*       ASSIGN                                                   !16, ~102
   62   154*       INIT_METHOD_CALL                                         !16, 'add'
        155*       SEND_VAR_EX                                              !12
        156*       DO_FCALL                                      0          
   63   157*       NEW                                              $105    'DatePeriod'
        158*       SEND_VAR_EX                                              !14
        159*       SEND_VAR_EX                                              !15
        160*       SEND_VAR_EX                                              !16
        161*       DO_FCALL                                      0          
        162*       ASSIGN                                                   !17, $105
   65   163*       FE_RESET_R                                       $108    !17, ->172
        164*       FE_FETCH_R                                               $108, !18, ->172
   66   165*       INIT_METHOD_CALL                                         !18, 'format'
        166*       SEND_VAL_EX                                              'Y-m-d'
        167*       DO_FCALL                                      0  $109    
        168*       CONCAT                                           ~110    '--', $109
        169*       CONCAT                                           ~111    ~110, '%0A'
        170*       ECHO                                                     ~111
   65   171*       JMP                                                      ->164
        172*       FE_FREE                                                  $108
   58   173*       JMP                                                      ->142
        174*       FE_FREE                                                  $97
   69   175*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.2 ms | 1408 KiB | 15 Q