3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start_date = '2019-01-01'; $end_date = '2019-12-31'; function makeBroadcastCalendar($start_date, $end_date) { $end = new DateTime($end_date); $start = new DateTime($start_date); $start->modify('monday this week'); $week = 1; $weeks = array(); while($start < $end) { $weeks[$week++] = $start->format('Y-m-d'); $start->modify('+1 week'); } return $weeks; } function getBroadcastMonth($date) { $end_of_week = new DateTime($date); $end_of_week->modify('sunday this week'); return (int)$end_of_week->format('n'); } function getBroadcastWeek($date) { $start = new DateTime($date); $start->modify('January 1'); $start->modify('monday this week'); $start_of_week = new DateTime($date); $start_of_week->modify('monday this week'); $week = 1; while ($start < $start_of_week) { $start->modify('+1 week'); $week++; } return $week; } function getFirstAndLast($year, $month) { $start = new DateTime("$year-$month-01"); $end = clone $start; $start->modify('monday this week'); $output = array('first_day' => $start->format('Y-m-d')); $end->modify('+1 month'); $end->modify('monday this week'); while ($start < $end) { $start->modify('+1 week'); } $output['end'] = $start->modify('-1 day')->format('Y-m-d'); return $output; } echo getBroadcastMonth('2019-10-12') . PHP_EOL; echo getBroadcastMonth('2019-10-29') . PHP_EOL; echo getBroadcastMonth('2019-05-31') . PHP_EOL; echo getBroadcastWeek('2019-10-12') . PHP_EOL; echo getBroadcastWeek('2019-10-29') . PHP_EOL; echo getBroadcastWeek('2019-05-31') . PHP_EOL; for ($i = 1; $i <= 12; $i++) { print_r(getFirstAndLast(2019, $i)); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 34
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 34
Branch analysis from position: 44
Branch analysis from position: 34
filename:       /in/llVTN
function name:  (null)
number of ops:  45
compiled vars:  !0 = $start_date, !1 = $end_date, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '2019-01-01'
    4     1        ASSIGN                                                   !1, '2019-12-31'
   53     2        INIT_FCALL                                               'getbroadcastmonth'
          3        SEND_VAL                                                 '2019-10-12'
          4        DO_FCALL                                      0  $5      
          5        CONCAT                                           ~6      $5, '%0A'
          6        ECHO                                                     ~6
   54     7        INIT_FCALL                                               'getbroadcastmonth'
          8        SEND_VAL                                                 '2019-10-29'
          9        DO_FCALL                                      0  $7      
         10        CONCAT                                           ~8      $7, '%0A'
         11        ECHO                                                     ~8
   55    12        INIT_FCALL                                               'getbroadcastmonth'
         13        SEND_VAL                                                 '2019-05-31'
         14        DO_FCALL                                      0  $9      
         15        CONCAT                                           ~10     $9, '%0A'
         16        ECHO                                                     ~10
   57    17        INIT_FCALL                                               'getbroadcastweek'
         18        SEND_VAL                                                 '2019-10-12'
         19        DO_FCALL                                      0  $11     
         20        CONCAT                                           ~12     $11, '%0A'
         21        ECHO                                                     ~12
   58    22        INIT_FCALL                                               'getbroadcastweek'
         23        SEND_VAL                                                 '2019-10-29'
         24        DO_FCALL                                      0  $13     
         25        CONCAT                                           ~14     $13, '%0A'
         26        ECHO                                                     ~14
   59    27        INIT_FCALL                                               'getbroadcastweek'
         28        SEND_VAL                                                 '2019-05-31'
         29        DO_FCALL                                      0  $15     
         30        CONCAT                                           ~16     $15, '%0A'
         31        ECHO                                                     ~16
   61    32        ASSIGN                                                   !2, 1
         33      > JMP                                                      ->42
   62    34    >   INIT_FCALL                                               'print_r'
         35        INIT_FCALL                                               'getfirstandlast'
         36        SEND_VAL                                                 2019
         37        SEND_VAR                                                 !2
         38        DO_FCALL                                      0  $18     
         39        SEND_VAR                                                 $18
         40        DO_ICALL                                                 
   61    41        PRE_INC                                                  !2
         42    >   IS_SMALLER_OR_EQUAL                                      !2, 12
         43      > JMPNZ                                                    ~21, ->34
   63    44    > > RETURN                                                   1

Function makebroadcastcalendar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 16
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 16
Branch analysis from position: 27
Branch analysis from position: 16
filename:       /in/llVTN
function name:  makeBroadcastCalendar
number of ops:  29
compiled vars:  !0 = $start_date, !1 = $end_date, !2 = $end, !3 = $start, !4 = $week, !5 = $weeks
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        NEW                                              $6      'DateTime'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $6
    8     6        NEW                                              $9      'DateTime'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $9
    9    10        INIT_METHOD_CALL                                         !3, 'modify'
         11        SEND_VAL_EX                                              'monday+this+week'
         12        DO_FCALL                                      0          
   10    13        ASSIGN                                                   !4, 1
   11    14        ASSIGN                                                   !5, <array>
   12    15      > JMP                                                      ->25
   13    16    >   POST_INC                                         ~15     !4
         17        INIT_METHOD_CALL                                         !3, 'format'
         18        SEND_VAL_EX                                              'Y-m-d'
         19        DO_FCALL                                      0  $17     
         20        ASSIGN_DIM                                               !5, ~15
         21        OP_DATA                                                  $17
   14    22        INIT_METHOD_CALL                                         !3, 'modify'
         23        SEND_VAL_EX                                              '%2B1+week'
         24        DO_FCALL                                      0          
   12    25    >   IS_SMALLER                                               !3, !2
         26      > JMPNZ                                                    ~19, ->16
   16    27    > > RETURN                                                   !5
   17    28*     > RETURN                                                   null

End of function makebroadcastcalendar

Function getbroadcastmonth:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/llVTN
function name:  getBroadcastMonth
number of ops:  14
compiled vars:  !0 = $date, !1 = $end_of_week
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        NEW                                              $2      'DateTime'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $2
   21     5        INIT_METHOD_CALL                                         !1, 'modify'
          6        SEND_VAL_EX                                              'sunday+this+week'
          7        DO_FCALL                                      0          
   22     8        INIT_METHOD_CALL                                         !1, 'format'
          9        SEND_VAL_EX                                              'n'
         10        DO_FCALL                                      0  $6      
         11        CAST                                          4  ~7      $6
         12      > RETURN                                                   ~7
   23    13*     > RETURN                                                   null

End of function getbroadcastmonth

Function getbroadcastweek:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 20
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 20
Branch analysis from position: 26
Branch analysis from position: 20
filename:       /in/llVTN
function name:  getBroadcastWeek
number of ops:  28
compiled vars:  !0 = $date, !1 = $start, !2 = $start_of_week, !3 = $week
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        NEW                                              $4      'DateTime'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $4
   27     5        INIT_METHOD_CALL                                         !1, 'modify'
          6        SEND_VAL_EX                                              'January+1'
          7        DO_FCALL                                      0          
   28     8        INIT_METHOD_CALL                                         !1, 'modify'
          9        SEND_VAL_EX                                              'monday+this+week'
         10        DO_FCALL                                      0          
   29    11        NEW                                              $9      'DateTime'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !2, $9
   30    15        INIT_METHOD_CALL                                         !2, 'modify'
         16        SEND_VAL_EX                                              'monday+this+week'
         17        DO_FCALL                                      0          
   31    18        ASSIGN                                                   !3, 1
   32    19      > JMP                                                      ->24
   33    20    >   INIT_METHOD_CALL                                         !1, 'modify'
         21        SEND_VAL_EX                                              '%2B1+week'
         22        DO_FCALL                                      0          
   34    23        PRE_INC                                                  !3
   32    24    >   IS_SMALLER                                               !1, !2
         25      > JMPNZ                                                    ~16, ->20
   36    26    > > RETURN                                                   !3
   37    27*     > RETURN                                                   null

End of function getbroadcastweek

Function getfirstandlast:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 27
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 27
Branch analysis from position: 32
Branch analysis from position: 27
filename:       /in/llVTN
function name:  getFirstAndLast
number of ops:  42
compiled vars:  !0 = $year, !1 = $month, !2 = $start, !3 = $end, !4 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        NEW                                              $5      'DateTime'
          3        ROPE_INIT                                     4  ~7      !0
          4        ROPE_ADD                                      1  ~7      ~7, '-'
          5        ROPE_ADD                                      2  ~7      ~7, !1
          6        ROPE_END                                      3  ~6      ~7, '-01'
          7        SEND_VAL_EX                                              ~6
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $5
   41    10        CLONE                                            ~11     !2
         11        ASSIGN                                                   !3, ~11
   42    12        INIT_METHOD_CALL                                         !2, 'modify'
         13        SEND_VAL_EX                                              'monday+this+week'
         14        DO_FCALL                                      0          
   43    15        INIT_METHOD_CALL                                         !2, 'format'
         16        SEND_VAL_EX                                              'Y-m-d'
         17        DO_FCALL                                      0  $14     
         18        INIT_ARRAY                                       ~15     $14, 'first_day'
         19        ASSIGN                                                   !4, ~15
   44    20        INIT_METHOD_CALL                                         !3, 'modify'
         21        SEND_VAL_EX                                              '%2B1+month'
         22        DO_FCALL                                      0          
   45    23        INIT_METHOD_CALL                                         !3, 'modify'
         24        SEND_VAL_EX                                              'monday+this+week'
         25        DO_FCALL                                      0          
   46    26      > JMP                                                      ->30
   47    27    >   INIT_METHOD_CALL                                         !2, 'modify'
         28        SEND_VAL_EX                                              '%2B1+week'
         29        DO_FCALL                                      0          
   46    30    >   IS_SMALLER                                               !2, !3
         31      > JMPNZ                                                    ~20, ->27
   49    32    >   INIT_METHOD_CALL                                         !2, 'modify'
         33        SEND_VAL_EX                                              '-1+day'
         34        DO_FCALL                                      0  $22     
         35        INIT_METHOD_CALL                                         $22, 'format'
         36        SEND_VAL_EX                                              'Y-m-d'
         37        DO_FCALL                                      0  $23     
         38        ASSIGN_DIM                                               !4, 'end'
         39        OP_DATA                                                  $23
   50    40      > RETURN                                                   !4
   51    41*     > RETURN                                                   null

End of function getfirstandlast

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.95 ms | 1017 KiB | 21 Q