3v4l.org

run code in 300+ PHP versions simultaneously
<?php $year = 2013; $month = 10; $week_nr_of_month = 3; // from 1 to 6 weeks in month $day_of_week = 0; // Sunday date("w") $start = new DateTime(); $start->setDate($year, $month, '1'); $end = clone $start; $end->modify('last day of month'); $interval = new DateInterval('P1D'); $period = new DatePeriod($start, $interval, $end); $week = 0; foreach ($period as $date) { if ($date->format('w') === $day_of_week) { $week++; if ($week_nr_of_month === $week) { // bingo! } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 39
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 39
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 38
Branch analysis from position: 38
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/eKD2n
function name:  (null)
number of ops:  41
compiled vars:  !0 = $year, !1 = $month, !2 = $week_nr_of_month, !3 = $day_of_week, !4 = $start, !5 = $end, !6 = $interval, !7 = $period, !8 = $week, !9 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 2013
    4     1        ASSIGN                                                   !1, 10
    5     2        ASSIGN                                                   !2, 3
    6     3        ASSIGN                                                   !3, 0
    8     4        NEW                                              $14     'DateTime'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !4, $14
    9     7        INIT_METHOD_CALL                                         !4, 'setDate'
          8        SEND_VAR_EX                                              !0
          9        SEND_VAR_EX                                              !1
         10        SEND_VAL_EX                                              '1'
         11        DO_FCALL                                      0          
   10    12        CLONE                                            ~18     !4
         13        ASSIGN                                                   !5, ~18
   11    14        INIT_METHOD_CALL                                         !5, 'modify'
         15        SEND_VAL_EX                                              'last+day+of+month'
         16        DO_FCALL                                      0          
   12    17        NEW                                              $21     'DateInterval'
         18        SEND_VAL_EX                                              'P1D'
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !6, $21
   13    21        NEW                                              $24     'DatePeriod'
         22        SEND_VAR_EX                                              !4
         23        SEND_VAR_EX                                              !6
         24        SEND_VAR_EX                                              !5
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !7, $24
   14    27        ASSIGN                                                   !8, 0
   15    28      > FE_RESET_R                                       $28     !7, ->39
         29    > > FE_FETCH_R                                               $28, !9, ->39
   16    30    >   INIT_METHOD_CALL                                         !9, 'format'
         31        SEND_VAL_EX                                              'w'
         32        DO_FCALL                                      0  $29     
         33        IS_IDENTICAL                                             !3, $29
         34      > JMPZ                                                     ~30, ->38
   17    35    >   PRE_INC                                                  !8
   18    36        IS_IDENTICAL                                             !2, !8
         37      > JMPZ                                                     ~32, ->38
   15    38    > > JMP                                                      ->29
         39    >   FE_FREE                                                  $28
   22    40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.4 ms | 1399 KiB | 13 Q