3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_weeks($month, $year) { $weeks = []; $ym = $year . '-' . $month; $final = date('t', strtotime($ym)); $firstSat = date('d', strtotime("first Saturday of $ym")); $d = 1; $weekNo = 0; do { $weekEnd = $d === 1 ? $firstSat : min($final, $d + 6); $weeks[] = sprintf( "Week %d: %s-%02d - %s-%02d", ++$weekNo, $ym, $d, $ym, $weekEnd ); $d = $weekEnd + 1; } while ($weekEnd < $final); return $weeks; } foreach (['01','02','03','04','05','06', '07', '08', '09', '10', '11', '12'] as $month) { echo var_export(get_weeks($month, '2020'), true) . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 1, Position 2 = 13
Branch analysis from position: 1
2 jumps found. (Code = 78) Position 1 = 2, Position 2 = 13
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 1
Branch analysis from position: 1
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/v1F2P
function name:  (null)
number of ops:  15
compiled vars:  !0 = $month
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E > > FE_RESET_R                                       $1      <array>, ->13
          1    > > FE_FETCH_R                                               $1, !0, ->13
   27     2    >   INIT_FCALL                                               'var_export'
          3        INIT_FCALL                                               'get_weeks'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 '2020'
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $3      
         10        CONCAT                                           ~4      $3, '%0A'
         11        ECHO                                                     ~4
   26    12      > JMP                                                      ->1
         13    >   FE_FREE                                                  $1
   28    14      > RETURN                                                   1

Function get_weeks:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 26
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 26
Branch analysis from position: 52
Branch analysis from position: 26
filename:       /in/v1F2P
function name:  get_weeks
number of ops:  54
compiled vars:  !0 = $month, !1 = $year, !2 = $weeks, !3 = $ym, !4 = $final, !5 = $firstSat, !6 = $d, !7 = $weekNo, !8 = $weekEnd
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3        CONCAT                                           ~10     !1, '-'
          4        CONCAT                                           ~11     ~10, !0
          5        ASSIGN                                                   !3, ~11
    6     6        INIT_FCALL                                               'date'
          7        SEND_VAL                                                 't'
          8        INIT_FCALL                                               'strtotime'
          9        SEND_VAR                                                 !3
         10        DO_ICALL                                         $13     
         11        SEND_VAR                                                 $13
         12        DO_ICALL                                         $14     
         13        ASSIGN                                                   !4, $14
    7    14        INIT_FCALL                                               'date'
         15        SEND_VAL                                                 'd'
         16        INIT_FCALL                                               'strtotime'
         17        NOP                                                      
         18        FAST_CONCAT                                      ~16     'first+Saturday+of+', !3
         19        SEND_VAL                                                 ~16
         20        DO_ICALL                                         $17     
         21        SEND_VAR                                                 $17
         22        DO_ICALL                                         $18     
         23        ASSIGN                                                   !5, $18
    8    24        ASSIGN                                                   !6, 1
    9    25        ASSIGN                                                   !7, 0
   12    26    >   IS_IDENTICAL                                             !6, 1
         27      > JMPZ                                                     ~22, ->30
         28    >   QM_ASSIGN                                        ~23     !5
         29      > JMP                                                      ->36
         30    >   INIT_FCALL                                               'min'
         31        SEND_VAR                                                 !4
         32        ADD                                              ~24     !6, 6
         33        SEND_VAL                                                 ~24
         34        DO_ICALL                                         $25     
         35        QM_ASSIGN                                        ~23     $25
         36    >   ASSIGN                                                   !8, ~23
   13    37        INIT_FCALL                                               'sprintf'
   14    38        SEND_VAL                                                 'Week+%25d%3A+%25s-%2502d+-+%25s-%2502d'
   15    39        PRE_INC                                          ~28     !7
         40        SEND_VAL                                                 ~28
   16    41        SEND_VAR                                                 !3
   17    42        SEND_VAR                                                 !6
   18    43        SEND_VAR                                                 !3
   19    44        SEND_VAR                                                 !8
   13    45        DO_ICALL                                         $29     
         46        ASSIGN_DIM                                               !2
   19    47        OP_DATA                                                  $29
   21    48        ADD                                              ~30     !8, 1
         49        ASSIGN                                                   !6, ~30
   22    50        IS_SMALLER                                               !8, !4
         51      > JMPNZ                                                    ~32, ->26
   24    52    > > RETURN                                                   !2
   25    53*     > RETURN                                                   null

End of function get_weeks

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.09 ms | 1465 KiB | 19 Q