3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generate_calendar($month, $year) { $calendar = []; $week_number = (IntlCalendar::fromDateTime ("$year-$month-01"))->get(IntlCalendar::FIELD_WEEK_OF_YEAR); $month_start = new DateTime("$year-$month-01"); // Generate the previous month's days if ($first_day = $month_start->format('w')) { $week = array_fill(1, $first_day, ''); } // Generate the current month's days $days_in_month = $month_start->format('t'); for ($i = 1; $i <= $days_in_month; $i++) { $week[] = $i; if (count($week) == 7) { $calendar[$week_number] = $week; $week_number++; $week = []; } } if ($week) { // Generate empty days for the next month $calendar[$week_number] = array_pad($week, 7, ''); } return $calendar; } foreach (range(2020, 2025) as $year) { foreach (range(1, 12) as $month) { $month_name = date('F', strtotime("$year-$month-01")); $calendar = generate_calendar($month, $year); echo "<table>\n"; echo " <tr>\n"; echo " <th colspan='8'>$month_name $year</th>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <th>Week</th>\n"; echo " <th>Sun</th>\n"; echo " <th>Mon</th>\n"; echo " <th>Tue</th>\n"; echo " <th>Wed</th>\n"; echo " <th>Thu</th>\n"; echo " <th>Fri</th>\n"; echo " <th>Sat</th>\n"; echo " </tr>\n"; foreach ($calendar as $week_number => $week) { echo " <tr>\n"; echo " <td>$week_number</td>\n"; foreach ($week as $day) { echo " <td>$day</td>\n"; } echo " </tr>\n"; } echo "</table>\n\n"; } }

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 71
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 71
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 69
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 69
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 49, Position 2 = 66
Branch analysis from position: 49
2 jumps found. (Code = 78) Position 1 = 50, Position 2 = 66
Branch analysis from position: 50
2 jumps found. (Code = 77) Position 1 = 57, Position 2 = 63
Branch analysis from position: 57
2 jumps found. (Code = 78) Position 1 = 58, Position 2 = 63
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 63
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 66
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 69
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
filename:       /in/fdFu5
function name:  (null)
number of ops:  73
compiled vars:  !0 = $year, !1 = $month, !2 = $month_name, !3 = $calendar, !4 = $week, !5 = $week_number, !6 = $day
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 2020
          2        SEND_VAL                                                 2025
          3        DO_ICALL                                         $7      
          4      > FE_RESET_R                                       $8      $7, ->71
          5    > > FE_FETCH_R                                               $8, !0, ->71
   34     6    >   INIT_FCALL                                               'range'
          7        SEND_VAL                                                 1
          8        SEND_VAL                                                 12
          9        DO_ICALL                                         $9      
         10      > FE_RESET_R                                       $10     $9, ->69
         11    > > FE_FETCH_R                                               $10, !1, ->69
   35    12    >   INIT_FCALL                                               'date'
         13        SEND_VAL                                                 'F'
         14        INIT_FCALL                                               'strtotime'
         15        ROPE_INIT                                     4  ~12     !0
         16        ROPE_ADD                                      1  ~12     ~12, '-'
         17        ROPE_ADD                                      2  ~12     ~12, !1
         18        ROPE_END                                      3  ~11     ~12, '-01'
         19        SEND_VAL                                                 ~11
         20        DO_ICALL                                         $14     
         21        SEND_VAR                                                 $14
         22        DO_ICALL                                         $15     
         23        ASSIGN                                                   !2, $15
   36    24        INIT_FCALL                                               'generate_calendar'
         25        SEND_VAR                                                 !1
         26        SEND_VAR                                                 !0
         27        DO_FCALL                                      0  $17     
         28        ASSIGN                                                   !3, $17
   38    29        ECHO                                                     '%3Ctable%3E%0A'
   39    30        ECHO                                                     '++%3Ctr%3E%0A'
   40    31        ROPE_INIT                                     5  ~20     '++++%3Cth+colspan%3D%278%27%3E'
         32        ROPE_ADD                                      1  ~20     ~20, !2
         33        ROPE_ADD                                      2  ~20     ~20, '+'
         34        ROPE_ADD                                      3  ~20     ~20, !0
         35        ROPE_END                                      4  ~19     ~20, '%3C%2Fth%3E%0A'
         36        ECHO                                                     ~19
   41    37        ECHO                                                     '++%3C%2Ftr%3E%0A'
   42    38        ECHO                                                     '++%3Ctr%3E%0A'
   43    39        ECHO                                                     '++++%3Cth%3EWeek%3C%2Fth%3E%0A'
   44    40        ECHO                                                     '++++%3Cth%3ESun%3C%2Fth%3E%0A'
   45    41        ECHO                                                     '++++%3Cth%3EMon%3C%2Fth%3E%0A'
   46    42        ECHO                                                     '++++%3Cth%3ETue%3C%2Fth%3E%0A'
   47    43        ECHO                                                     '++++%3Cth%3EWed%3C%2Fth%3E%0A'
   48    44        ECHO                                                     '++++%3Cth%3EThu%3C%2Fth%3E%0A'
   49    45        ECHO                                                     '++++%3Cth%3EFri%3C%2Fth%3E%0A'
   50    46        ECHO                                                     '++++%3Cth%3ESat%3C%2Fth%3E%0A'
   51    47        ECHO                                                     '++%3C%2Ftr%3E%0A'
   53    48      > FE_RESET_R                                       $23     !3, ->66
         49    > > FE_FETCH_R                                       ~24     $23, !4, ->66
         50    >   ASSIGN                                                   !5, ~24
   54    51        ECHO                                                     '++%3Ctr%3E%0A'
   55    52        ROPE_INIT                                     3  ~27     '++++%3Ctd%3E'
         53        ROPE_ADD                                      1  ~27     ~27, !5
         54        ROPE_END                                      2  ~26     ~27, '%3C%2Ftd%3E%0A'
         55        ECHO                                                     ~26
   56    56      > FE_RESET_R                                       $29     !4, ->63
         57    > > FE_FETCH_R                                               $29, !6, ->63
   57    58    >   ROPE_INIT                                     3  ~31     '++++%3Ctd%3E'
         59        ROPE_ADD                                      1  ~31     ~31, !6
         60        ROPE_END                                      2  ~30     ~31, '%3C%2Ftd%3E%0A'
         61        ECHO                                                     ~30
   56    62      > JMP                                                      ->57
         63    >   FE_FREE                                                  $29
   59    64        ECHO                                                     '++%3C%2Ftr%3E%0A'
   53    65      > JMP                                                      ->49
         66    >   FE_FREE                                                  $23
   62    67        ECHO                                                     '%3C%2Ftable%3E%0A%0A'
   34    68      > JMP                                                      ->11
         69    >   FE_FREE                                                  $10
   33    70      > JMP                                                      ->5
         71    >   FE_FREE                                                  $8
   64    72      > RETURN                                                   1

Function generate_calendar:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 40
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 60
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 49
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 40
Branch analysis from position: 52
Branch analysis from position: 40
Branch analysis from position: 49
Branch analysis from position: 34
filename:       /in/fdFu5
function name:  generate_calendar
number of ops:  62
compiled vars:  !0 = $month, !1 = $year, !2 = $calendar, !3 = $week_number, !4 = $month_start, !5 = $first_day, !6 = $week, !7 = $days_in_month, !8 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    6     3        INIT_STATIC_METHOD_CALL                                  'IntlCalendar', 'fromDateTime'
          4        ROPE_INIT                                     4  ~11     !1
          5        ROPE_ADD                                      1  ~11     ~11, '-'
          6        ROPE_ADD                                      2  ~11     ~11, !0
          7        ROPE_END                                      3  ~10     ~11, '-01'
          8        SEND_VAL_EX                                              ~10
          9        DO_FCALL                                      0  $13     
         10        INIT_METHOD_CALL                                         $13, 'get'
         11        FETCH_CLASS_CONSTANT                             ~14     'IntlCalendar', 'FIELD_WEEK_OF_YEAR'
         12        SEND_VAL_EX                                              ~14
         13        DO_FCALL                                      0  $15     
         14        ASSIGN                                                   !3, $15
    7    15        NEW                                              $17     'DateTime'
         16        ROPE_INIT                                     4  ~19     !1
         17        ROPE_ADD                                      1  ~19     ~19, '-'
         18        ROPE_ADD                                      2  ~19     ~19, !0
         19        ROPE_END                                      3  ~18     ~19, '-01'
         20        SEND_VAL_EX                                              ~18
         21        DO_FCALL                                      0          
         22        ASSIGN                                                   !4, $17
   10    23        INIT_METHOD_CALL                                         !4, 'format'
         24        SEND_VAL_EX                                              'w'
         25        DO_FCALL                                      0  $23     
         26        ASSIGN                                           ~24     !5, $23
         27      > JMPZ                                                     ~24, ->34
   11    28    >   INIT_FCALL                                               'array_fill'
         29        SEND_VAL                                                 1
         30        SEND_VAR                                                 !5
         31        SEND_VAL                                                 ''
         32        DO_ICALL                                         $25     
         33        ASSIGN                                                   !6, $25
   15    34    >   INIT_METHOD_CALL                                         !4, 'format'
         35        SEND_VAL_EX                                              't'
         36        DO_FCALL                                      0  $27     
         37        ASSIGN                                                   !7, $27
   16    38        ASSIGN                                                   !8, 1
         39      > JMP                                                      ->50
   17    40    >   ASSIGN_DIM                                               !6
         41        OP_DATA                                                  !8
   18    42        COUNT                                            ~31     !6
         43        IS_EQUAL                                                 ~31, 7
         44      > JMPZ                                                     ~32, ->49
   19    45    >   ASSIGN_DIM                                               !2, !3
         46        OP_DATA                                                  !6
   20    47        PRE_INC                                                  !3
   21    48        ASSIGN                                                   !6, <array>
   16    49    >   PRE_INC                                                  !8
         50    >   IS_SMALLER_OR_EQUAL                                      !8, !7
         51      > JMPNZ                                                    ~37, ->40
   25    52    > > JMPZ                                                     !6, ->60
   27    53    >   INIT_FCALL                                               'array_pad'
         54        SEND_VAR                                                 !6
         55        SEND_VAL                                                 7
         56        SEND_VAL                                                 ''
         57        DO_ICALL                                         $39     
         58        ASSIGN_DIM                                               !2, !3
         59        OP_DATA                                                  $39
   30    60    > > RETURN                                                   !2
   31    61*     > RETURN                                                   null

End of function generate_calendar

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.66 ms | 1017 KiB | 19 Q