3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isMonday($date) { return $date->format('N') === '1'; } function isSunday($date) { return $date->format('N') === '7'; } function getMondays($start, $end) { $mondays = []; $datePeriod = new DatePeriod($start, new DateInterval('P1D'), $end); foreach ($datePeriod as $date) { if (isMonday($date)) $mondays[] = $date; } if (!isSunday($end)) array_pop($mondays); return $mondays; } $startDate = new DateTime('2021-06-20'); $endDate = new DateTime('2021-07-07'); var_dump(getMondays($startDate, $endDate));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Il6Db
function name:  (null)
number of ops:  16
compiled vars:  !0 = $startDate, !1 = $endDate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   NEW                                              $2      'DateTime'
          1        SEND_VAL_EX                                              '2021-06-20'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   23     4        NEW                                              $5      'DateTime'
          5        SEND_VAL_EX                                              '2021-07-07'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $5
   24     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'getmondays'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $8      
         13        SEND_VAR                                                 $8
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Function ismonday:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Il6Db
function name:  isMonday
number of ops:  7
compiled vars:  !0 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_METHOD_CALL                                         !0, 'format'
          2        SEND_VAL_EX                                              'N'
          3        DO_FCALL                                      0  $1      
          4        IS_IDENTICAL                                     ~2      $1, '1'
          5      > RETURN                                                   ~2
    5     6*     > RETURN                                                   null

End of function ismonday

Function issunday:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Il6Db
function name:  isSunday
number of ops:  7
compiled vars:  !0 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_METHOD_CALL                                         !0, 'format'
          2        SEND_VAL_EX                                              'N'
          3        DO_FCALL                                      0  $1      
          4        IS_IDENTICAL                                     ~2      $1, '7'
          5      > RETURN                                                   ~2
    9     6*     > RETURN                                                   null

End of function issunday

Function getmondays:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 20
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 21
filename:       /in/Il6Db
function name:  getMondays
number of ops:  32
compiled vars:  !0 = $start, !1 = $end, !2 = $mondays, !3 = $datePeriod, !4 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        ASSIGN                                                   !2, <array>
   14     3        NEW                                              $6      'DatePeriod'
          4        SEND_VAR_EX                                              !0
          5        NEW                                              $7      'DateInterval'
          6        SEND_VAL_EX                                              'P1D'
          7        DO_FCALL                                      0          
          8        SEND_VAR_NO_REF_EX                                       $7
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !3, $6
   15    12      > FE_RESET_R                                       $11     !3, ->21
         13    > > FE_FETCH_R                                               $11, !4, ->21
   16    14    >   INIT_FCALL                                               'ismonday'
         15        SEND_VAR                                                 !4
         16        DO_FCALL                                      0  $12     
         17      > JMPZ                                                     $12, ->20
         18    >   ASSIGN_DIM                                               !2
         19        OP_DATA                                                  !4
   15    20    > > JMP                                                      ->13
         21    >   FE_FREE                                                  $11
   18    22        INIT_FCALL                                               'issunday'
         23        SEND_VAR                                                 !1
         24        DO_FCALL                                      0  $14     
         25        BOOL_NOT                                         ~15     $14
         26      > JMPZ                                                     ~15, ->30
         27    >   INIT_FCALL                                               'array_pop'
         28        SEND_REF                                                 !2
         29        DO_ICALL                                                 
   19    30    > > RETURN                                                   !2
   20    31*     > RETURN                                                   null

End of function getmondays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.08 ms | 1018 KiB | 18 Q