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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.9 ms | 1408 KiB | 15 Q