3v4l.org

run code in 300+ PHP versions simultaneously
<?php // the month to render and day to highlight $today = new DateTime(); // we'll need these to check if we're at the day we need to highlight // or if we're rendering a date that's outside $today's month $currentDay = $today->format('j'); $currentMonth = $today->format('n'); $daysInCurrentMonth = $today->format('t'); // figure out what Monday needs to kick off our table $date = (clone $today)->modify('first day of this month'); if ($date->format('w') != 1) { $date->modify('previous monday'); } $shouldStopRendering = false; echo '<table border="1">' . PHP_EOL; while (!$shouldStopRendering) { $weekDay = $date->format('w'); $month = $date->format('n'); $day = $date->format('j'); // start a new table row every time we hit a Monday, note that // since we forced $date to be a Monday above, our table should // now always start with a <tr> if ($weekDay == 1) { echo ' <tr>' . PHP_EOL; } if ($month != $currentMonth) { // we're either at the beginning or end of our table echo ' <td>&nbsp;</td>' . PHP_EOL; } else if ($day == $currentDay) { // highlight the current date echo ' <td bgcolor="#ff0000">' . $day . '</td>' . PHP_EOL; } else { echo ' <td>' . $day . '</td>' . PHP_EOL; } if ($weekDay == 0) { // every time we hit a Sunday, close the current table row echo ' </tr>' . PHP_EOL; // on a Sunday, if we've gone outside the current month **or** // this Sunday happens to be the last day we need to render, // stop looping so we can close the table if ($month != $currentMonth || $day == $daysInCurrentMonth) { $shouldStopRendering = true; } } // move on to the next day we need to display $date->modify('+1 day'); } echo '</table>';
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 31
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 46
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 50
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 70
Branch analysis from position: 63
2 jumps found. (Code = 47) Position 1 = 66, Position 2 = 68
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 70
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 31
Branch analysis from position: 75
Branch analysis from position: 31
Branch analysis from position: 70
Branch analysis from position: 68
Branch analysis from position: 70
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 70
Branch analysis from position: 63
Branch analysis from position: 70
Branch analysis from position: 46
Branch analysis from position: 28
filename:       /in/Z89i8
function name:  (null)
number of ops:  77
compiled vars:  !0 = $today, !1 = $currentDay, !2 = $currentMonth, !3 = $daysInCurrentMonth, !4 = $date, !5 = $shouldStopRendering, !6 = $weekDay, !7 = $month, !8 = $day
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $9      'DateTime'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $9
    7     3        INIT_METHOD_CALL                                         !0, 'format'
          4        SEND_VAL_EX                                              'j'
          5        DO_FCALL                                      0  $12     
          6        ASSIGN                                                   !1, $12
    8     7        INIT_METHOD_CALL                                         !0, 'format'
          8        SEND_VAL_EX                                              'n'
          9        DO_FCALL                                      0  $14     
         10        ASSIGN                                                   !2, $14
    9    11        INIT_METHOD_CALL                                         !0, 'format'
         12        SEND_VAL_EX                                              't'
         13        DO_FCALL                                      0  $16     
         14        ASSIGN                                                   !3, $16
   12    15        CLONE                                            ~18     !0
         16        INIT_METHOD_CALL                                         ~18, 'modify'
         17        SEND_VAL_EX                                              'first+day+of+this+month'
         18        DO_FCALL                                      0  $19     
         19        ASSIGN                                                   !4, $19
   13    20        INIT_METHOD_CALL                                         !4, 'format'
         21        SEND_VAL_EX                                              'w'
         22        DO_FCALL                                      0  $21     
         23        IS_NOT_EQUAL                                             $21, 1
         24      > JMPZ                                                     ~22, ->28
   14    25    >   INIT_METHOD_CALL                                         !4, 'modify'
         26        SEND_VAL_EX                                              'previous+monday'
         27        DO_FCALL                                      0          
   17    28    >   ASSIGN                                                   !5, <false>
   19    29        ECHO                                                     '%3Ctable+border%3D%221%22%3E%0A'
   20    30      > JMP                                                      ->73
   21    31    >   INIT_METHOD_CALL                                         !4, 'format'
         32        SEND_VAL_EX                                              'w'
         33        DO_FCALL                                      0  $25     
         34        ASSIGN                                                   !6, $25
   22    35        INIT_METHOD_CALL                                         !4, 'format'
         36        SEND_VAL_EX                                              'n'
         37        DO_FCALL                                      0  $27     
         38        ASSIGN                                                   !7, $27
   23    39        INIT_METHOD_CALL                                         !4, 'format'
         40        SEND_VAL_EX                                              'j'
         41        DO_FCALL                                      0  $29     
         42        ASSIGN                                                   !8, $29
   28    43        IS_EQUAL                                                 !6, 1
         44      > JMPZ                                                     ~31, ->46
   29    45    >   ECHO                                                     '++++%3Ctr%3E%0A'
   32    46    >   IS_NOT_EQUAL                                             !7, !2
         47      > JMPZ                                                     ~32, ->50
   34    48    >   ECHO                                                     '++++++++%3Ctd%3E%26nbsp%3B%3C%2Ftd%3E%0A'
   32    49      > JMP                                                      ->61
   35    50    >   IS_EQUAL                                                 !8, !1
         51      > JMPZ                                                     ~33, ->57
   37    52    >   CONCAT                                           ~34     '++++++++%3Ctd+bgcolor%3D%22%23ff0000%22%3E', !8
         53        CONCAT                                           ~35     ~34, '%3C%2Ftd%3E'
         54        CONCAT                                           ~36     ~35, '%0A'
         55        ECHO                                                     ~36
   35    56      > JMP                                                      ->61
   39    57    >   CONCAT                                           ~37     '++++++++%3Ctd%3E', !8
         58        CONCAT                                           ~38     ~37, '%3C%2Ftd%3E'
         59        CONCAT                                           ~39     ~38, '%0A'
         60        ECHO                                                     ~39
   42    61    >   IS_EQUAL                                                 !6, 0
         62      > JMPZ                                                     ~40, ->70
   44    63    >   ECHO                                                     '++++%3C%2Ftr%3E%0A'
   49    64        IS_NOT_EQUAL                                     ~41     !7, !2
         65      > JMPNZ_EX                                         ~41     ~41, ->68
         66    >   IS_EQUAL                                         ~42     !8, !3
         67        BOOL                                             ~41     ~42
         68    > > JMPZ                                                     ~41, ->70
   50    69    >   ASSIGN                                                   !5, <true>
   55    70    >   INIT_METHOD_CALL                                         !4, 'modify'
         71        SEND_VAL_EX                                              '%2B1+day'
         72        DO_FCALL                                      0          
   20    73    >   BOOL_NOT                                         ~45     !5
         74      > JMPNZ                                                    ~45, ->31
   57    75    >   ECHO                                                     '%3C%2Ftable%3E'
         76      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.71 ms | 1006 KiB | 13 Q