3v4l.org

run code in 300+ PHP versions simultaneously
<?php function work_days_between_two_dates(\DateTime $begin, \DateTime $end) { $workdays = []; $all_days = new DatePeriod($begin, new DateInterval('P1D'), $end); foreach ($all_days as $day) { $dow = (int)$day->format('w'); $dom = (int)$day->format('j'); if (1 <= $dow && $dow <= 5) { // Mon - Fri $workdays[] = $day; } else if (6 == $dow && 0 == $dom % 2) { // Even Saturday $workdays[] = $day; } } return $workdays; } $begin = new \DateTime('2015-11-01'); $end = new \DateTime('2015-12-01'); $days = work_days_between_two_dates($begin, $end); foreach ($days as $day) { echo $day->format('Y-m-d') . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/khZSa
function name:  (null)
number of ops:  23
compiled vars:  !0 = $begin, !1 = $end, !2 = $days, !3 = $day
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $4      'DateTime'
          1        SEND_VAL_EX                                              '2015-11-01'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $4
   19     4        NEW                                              $7      'DateTime'
          5        SEND_VAL_EX                                              '2015-12-01'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $7
   20     8        INIT_FCALL                                               'work_days_between_two_dates'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !2, $10
   21    13      > FE_RESET_R                                       $12     !2, ->21
         14    > > FE_FETCH_R                                               $12, !3, ->21
   22    15    >   INIT_METHOD_CALL                                         !3, 'format'
         16        SEND_VAL_EX                                              'Y-m-d'
         17        DO_FCALL                                      0  $13     
         18        CONCAT                                           ~14     $13, '%0A'
         19        ECHO                                                     ~14
   21    20      > JMP                                                      ->14
         21    >   FE_FREE                                                  $12
   23    22      > RETURN                                                   1

Function work_days_between_two_dates:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 41
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 41
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 32
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 40
Branch analysis from position: 37
Branch analysis from position: 28
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/khZSa
function name:  work_days_between_two_dates
number of ops:  44
compiled vars:  !0 = $begin, !1 = $end, !2 = $workdays, !3 = $all_days, !4 = $day, !5 = $dow, !6 = $dom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3        NEW                                              $8      'DatePeriod'
          4        SEND_VAR_EX                                              !0
          5        NEW                                              $9      'DateInterval'
          6        SEND_VAL_EX                                              'P1D'
          7        DO_FCALL                                      0          
          8        SEND_VAR_NO_REF_EX                                       $9
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !3, $8
    6    12      > FE_RESET_R                                       $13     !3, ->41
         13    > > FE_FETCH_R                                               $13, !4, ->41
    7    14    >   INIT_METHOD_CALL                                         !4, 'format'
         15        SEND_VAL_EX                                              'w'
         16        DO_FCALL                                      0  $14     
         17        CAST                                          4  ~15     $14
         18        ASSIGN                                                   !5, ~15
    8    19        INIT_METHOD_CALL                                         !4, 'format'
         20        SEND_VAL_EX                                              'j'
         21        DO_FCALL                                      0  $17     
         22        CAST                                          4  ~18     $17
         23        ASSIGN                                                   !6, ~18
    9    24        IS_SMALLER_OR_EQUAL                              ~20     1, !5
         25      > JMPZ_EX                                          ~20     ~20, ->28
         26    >   IS_SMALLER_OR_EQUAL                              ~21     !5, 5
         27        BOOL                                             ~20     ~21
         28    > > JMPZ                                                     ~20, ->32
   10    29    >   ASSIGN_DIM                                               !2
         30        OP_DATA                                                  !4
         31      > JMP                                                      ->40
   11    32    >   IS_EQUAL                                         ~23     !5, 6
         33      > JMPZ_EX                                          ~23     ~23, ->37
         34    >   MOD                                              ~24     !6, 2
         35        IS_EQUAL                                         ~25     ~24, 0
         36        BOOL                                             ~23     ~25
         37    > > JMPZ                                                     ~23, ->40
   12    38    >   ASSIGN_DIM                                               !2
         39        OP_DATA                                                  !4
    6    40    > > JMP                                                      ->13
         41    >   FE_FREE                                                  $13
   15    42      > RETURN                                                   !2
   16    43*     > RETURN                                                   null

End of function work_days_between_two_dates

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.19 ms | 1403 KiB | 14 Q