3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = new DateTime('2017-05-23'); $end = new DateTime('2017-06-21'); $dates = every_two_weeks($start, $end, ['tue', 'wed', 'sat']); foreach ($dates as $date) { echo $date->format('Y-m-d D').PHP_EOL; } function every_two_weeks($start, $end, $days) { $dates = []; $mon = new DateTime('mon this week '.$start->format('Y-m-d')); while ($mon <= $end) { $of = 'this week '.$mon->format('Y-m-d'); foreach ($days as $day) { $date = new DateTime("$day $of"); if ($date < $start) { continue; } if ($date > $end) { break 2; } $dates[] = $date; } $mon->add(new DateInterval('P2W')); } return $dates; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/q4RGg
function name:  (null)
number of ops:  24
compiled vars:  !0 = $start, !1 = $end, !2 = $dates, !3 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $4      'DateTime'
          1        SEND_VAL_EX                                              '2017-05-23'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $4
    4     4        NEW                                              $7      'DateTime'
          5        SEND_VAL_EX                                              '2017-06-21'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $7
    6     8        INIT_FCALL_BY_NAME                                       'every_two_weeks'
          9        SEND_VAR_EX                                              !0
         10        SEND_VAR_EX                                              !1
         11        SEND_VAL_EX                                              <array>
         12        DO_FCALL                                      0  $10     
         13        ASSIGN                                                   !2, $10
    8    14      > FE_RESET_R                                       $12     !2, ->22
         15    > > FE_FETCH_R                                               $12, !3, ->22
    9    16    >   INIT_METHOD_CALL                                         !3, 'format'
         17        SEND_VAL_EX                                              'Y-m-d+D'
         18        DO_FCALL                                      0  $13     
         19        CONCAT                                           ~14     $13, '%0A'
         20        ECHO                                                     ~14
    8    21      > JMP                                                      ->15
         22    >   FE_FREE                                                  $12
   39    23      > RETURN                                                   1

Function every_two_weeks:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 13
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 37
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 37
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 13
Branch analysis from position: 46
Branch analysis from position: 13
Branch analysis from position: 37
filename:       /in/q4RGg
function name:  every_two_weeks
number of ops:  48
compiled vars:  !0 = $start, !1 = $end, !2 = $days, !3 = $dates, !4 = $mon, !5 = $of, !6 = $day, !7 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   14     3        ASSIGN                                                   !3, <array>
   16     4        NEW                                              $9      'DateTime'
          5        INIT_METHOD_CALL                                         !0, 'format'
          6        SEND_VAL_EX                                              'Y-m-d'
          7        DO_FCALL                                      0  $10     
          8        CONCAT                                           ~11     'mon+this+week+', $10
          9        SEND_VAL_EX                                              ~11
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !4, $9
   18    12      > JMP                                                      ->44
   19    13    >   INIT_METHOD_CALL                                         !4, 'format'
         14        SEND_VAL_EX                                              'Y-m-d'
         15        DO_FCALL                                      0  $14     
         16        CONCAT                                           ~15     'this+week+', $14
         17        ASSIGN                                                   !5, ~15
   21    18      > FE_RESET_R                                       $17     !2, ->37
         19    > > FE_FETCH_R                                               $17, !6, ->37
   22    20    >   NEW                                              $18     'DateTime'
         21        ROPE_INIT                                     3  ~20     !6
         22        ROPE_ADD                                      1  ~20     ~20, '+'
         23        ROPE_END                                      2  ~19     ~20, !5
         24        SEND_VAL_EX                                              ~19
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !7, $18
   24    27        IS_SMALLER                                               !7, !0
         28      > JMPZ                                                     ~24, ->30
   25    29    > > JMP                                                      ->19
   28    30    >   IS_SMALLER                                               !1, !7
         31      > JMPZ                                                     ~25, ->34
   29    32    >   FE_FREE                                                  $17
         33      > JMP                                                      ->46
   32    34    >   ASSIGN_DIM                                               !3
         35        OP_DATA                                                  !7
   21    36      > JMP                                                      ->19
         37    >   FE_FREE                                                  $17
   35    38        INIT_METHOD_CALL                                         !4, 'add'
         39        NEW                                              $27     'DateInterval'
         40        SEND_VAL_EX                                              'P2W'
         41        DO_FCALL                                      0          
         42        SEND_VAR_NO_REF_EX                                       $27
         43        DO_FCALL                                      0          
   18    44    >   IS_SMALLER_OR_EQUAL                                      !4, !1
         45      > JMPNZ                                                    ~30, ->13
   38    46    > > RETURN                                                   !3
   39    47*     > RETURN                                                   null

End of function every_two_weeks

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.92 ms | 1442 KiB | 14 Q