3v4l.org

run code in 300+ PHP versions simultaneously
<?php $month = '2'; $year = '2017'; $lastDayOfWeek = '7'; //1 (for monday) to 7 (for sunday) function getWeeksInMonth($year, $month, $lastDayOfWeek, $format = 'Y/m/d') { $aWeeksOfMonth = []; $date = new DateTime("{$year}-{$month}-01"); $iDaysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year); $aOneWeek = [$date->format($format)]; $weekNumber = 1; for ($i = 1; $i <= $iDaysInMonth; $i++) { if ($lastDayOfWeek == $date->format('N') || $i == $iDaysInMonth) { $aOneWeek[] = $date->format($format); $aWeeksOfMonth[$weekNumber++] = $aOneWeek; $date->add(new DateInterval('P1D')); $aOneWeek = [$date->format($format)]; $i++; } $date->add(new DateInterval('P1D')); } return $aWeeksOfMonth; } $weeks = getWeeksInMonth($year, $month, $lastDayOfWeek); foreach($weeks as $weekNumber => $week){ echo "Week {$weekNumber}: {$week[0]} - {$week[1]}\r\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 23
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/1NGgR
function name:  (null)
number of ops:  25
compiled vars:  !0 = $month, !1 = $year, !2 = $lastDayOfWeek, !3 = $weeks, !4 = $week, !5 = $weekNumber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '2'
    4     1        ASSIGN                                                   !1, '2017'
    5     2        ASSIGN                                                   !2, '7'
   30     3        INIT_FCALL                                               'getweeksinmonth'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0  $9      
          8        ASSIGN                                                   !3, $9
   32     9      > FE_RESET_R                                       $11     !3, ->23
         10    > > FE_FETCH_R                                       ~12     $11, !4, ->23
         11    >   ASSIGN                                                   !5, ~12
   33    12        ROPE_INIT                                     7  ~17     'Week+'
         13        ROPE_ADD                                      1  ~17     ~17, !5
         14        ROPE_ADD                                      2  ~17     ~17, '%3A+'
         15        FETCH_DIM_R                                      ~14     !4, 0
         16        ROPE_ADD                                      3  ~17     ~17, ~14
         17        ROPE_ADD                                      4  ~17     ~17, '+-+'
         18        FETCH_DIM_R                                      ~15     !4, 1
         19        ROPE_ADD                                      5  ~17     ~17, ~15
         20        ROPE_END                                      6  ~16     ~17, '%0D%0A'
         21        ECHO                                                     ~16
   32    22      > JMP                                                      ->10
         23    >   FE_FREE                                                  $11
   34    24      > RETURN                                                   1

Function getweeksinmonth:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 28
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
2 jumps found. (Code = 47) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 56
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 28
Branch analysis from position: 65
Branch analysis from position: 28
Branch analysis from position: 56
Branch analysis from position: 35
filename:       /in/1NGgR
function name:  getWeeksInMonth
number of ops:  67
compiled vars:  !0 = $year, !1 = $month, !2 = $lastDayOfWeek, !3 = $format, !4 = $aWeeksOfMonth, !5 = $date, !6 = $iDaysInMonth, !7 = $aOneWeek, !8 = $weekNumber, !9 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      'Y%2Fm%2Fd'
    9     4        ASSIGN                                                   !4, <array>
   10     5        NEW                                              $11     'DateTime'
          6        ROPE_INIT                                     4  ~13     !0
          7        ROPE_ADD                                      1  ~13     ~13, '-'
          8        ROPE_ADD                                      2  ~13     ~13, !1
          9        ROPE_END                                      3  ~12     ~13, '-01'
         10        SEND_VAL_EX                                              ~12
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !5, $11
   11    13        INIT_FCALL_BY_NAME                                       'cal_days_in_month'
         14        FETCH_CONSTANT                                   ~17     'CAL_GREGORIAN'
         15        SEND_VAL_EX                                              ~17
         16        SEND_VAR_EX                                              !1
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0  $18     
         19        ASSIGN                                                   !6, $18
   12    20        INIT_METHOD_CALL                                         !5, 'format'
         21        SEND_VAR_EX                                              !3
         22        DO_FCALL                                      0  $20     
         23        INIT_ARRAY                                       ~21     $20
         24        ASSIGN                                                   !7, ~21
   13    25        ASSIGN                                                   !8, 1
   14    26        ASSIGN                                                   !9, 1
         27      > JMP                                                      ->63
   16    28    >   INIT_METHOD_CALL                                         !5, 'format'
         29        SEND_VAL_EX                                              'N'
         30        DO_FCALL                                      0  $25     
         31        IS_EQUAL                                         ~26     !2, $25
         32      > JMPNZ_EX                                         ~26     ~26, ->35
         33    >   IS_EQUAL                                         ~27     !9, !6
         34        BOOL                                             ~26     ~27
         35    > > JMPZ                                                     ~26, ->56
   18    36    >   INIT_METHOD_CALL                                         !5, 'format'
         37        SEND_VAR_EX                                              !3
         38        DO_FCALL                                      0  $29     
         39        ASSIGN_DIM                                               !7
         40        OP_DATA                                                  $29
   19    41        POST_INC                                         ~30     !8
         42        ASSIGN_DIM                                               !4, ~30
         43        OP_DATA                                                  !7
   20    44        INIT_METHOD_CALL                                         !5, 'add'
         45        NEW                                              $32     'DateInterval'
         46        SEND_VAL_EX                                              'P1D'
         47        DO_FCALL                                      0          
         48        SEND_VAR_NO_REF_EX                                       $32
         49        DO_FCALL                                      0          
   21    50        INIT_METHOD_CALL                                         !5, 'format'
         51        SEND_VAR_EX                                              !3
         52        DO_FCALL                                      0  $35     
         53        INIT_ARRAY                                       ~36     $35
         54        ASSIGN                                                   !7, ~36
   22    55        PRE_INC                                                  !9
   25    56    >   INIT_METHOD_CALL                                         !5, 'add'
         57        NEW                                              $39     'DateInterval'
         58        SEND_VAL_EX                                              'P1D'
         59        DO_FCALL                                      0          
         60        SEND_VAR_NO_REF_EX                                       $39
         61        DO_FCALL                                      0          
   14    62        PRE_INC                                                  !9
         63    >   IS_SMALLER_OR_EQUAL                                      !9, !6
         64      > JMPNZ                                                    ~43, ->28
   27    65    > > RETURN                                                   !4
   28    66*     > RETURN                                                   null

End of function getweeksinmonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
221.25 ms | 1012 KiB | 14 Q