3v4l.org

run code in 300+ PHP versions simultaneously
<?php $i = 1; // week number starts at 1 $date1 = new DateTime('2018-03-21'); $date2 = new DateTime('2018-05-14'); while (true) { echo "Week {$i}\n"; echo $date1->format('Y-m-d'), ' - '; $date1->modify('next saturday'); if ($date1 >= $date2) { echo $date2->format('Y-m-d'); break; // stop the loop, reached the end date, echo the last date, or whatever you want } echo $date1->format('Y-m-d') , "\n"; $date1->modify('next monday'); // start again on monday $i++; // increment for next week }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 10
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 29
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 10
Branch analysis from position: 39
Branch analysis from position: 10
filename:       /in/A31PJ
function name:  (null)
number of ops:  40
compiled vars:  !0 = $i, !1 = $date1, !2 = $date2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 1
    4     1        NEW                                              $4      'DateTime'
          2        SEND_VAL_EX                                              '2018-03-21'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $4
    5     5        NEW                                              $7      'DateTime'
          6        SEND_VAL_EX                                              '2018-05-14'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $7
    6     9      > JMP                                                      ->38
    7    10    >   ROPE_INIT                                     3  ~11     'Week+'
         11        ROPE_ADD                                      1  ~11     ~11, !0
         12        ROPE_END                                      2  ~10     ~11, '%0A'
         13        ECHO                                                     ~10
    8    14        INIT_METHOD_CALL                                         !1, 'format'
         15        SEND_VAL_EX                                              'Y-m-d'
         16        DO_FCALL                                      0  $13     
         17        ECHO                                                     $13
         18        ECHO                                                     '+-+'
    9    19        INIT_METHOD_CALL                                         !1, 'modify'
         20        SEND_VAL_EX                                              'next+saturday'
         21        DO_FCALL                                      0          
   10    22        IS_SMALLER_OR_EQUAL                                      !2, !1
         23      > JMPZ                                                     ~15, ->29
   11    24    >   INIT_METHOD_CALL                                         !2, 'format'
         25        SEND_VAL_EX                                              'Y-m-d'
         26        DO_FCALL                                      0  $16     
         27        ECHO                                                     $16
   12    28      > JMP                                                      ->39
   14    29    >   INIT_METHOD_CALL                                         !1, 'format'
         30        SEND_VAL_EX                                              'Y-m-d'
         31        DO_FCALL                                      0  $17     
         32        ECHO                                                     $17
         33        ECHO                                                     '%0A'
   15    34        INIT_METHOD_CALL                                         !1, 'modify'
         35        SEND_VAL_EX                                              'next+monday'
         36        DO_FCALL                                      0          
   16    37        PRE_INC                                                  !0
    6    38    > > JMPNZ                                                    <true>, ->10
   17    39    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.54 ms | 1403 KiB | 13 Q