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->modify('+1 day')); 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-11-14'); $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/vrhsa
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-11-14'
          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 = 16, Position 2 = 44
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 44
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 40
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 43
Branch analysis from position: 40
Branch analysis from position: 31
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/vrhsa
function name:  work_days_between_two_dates
number of ops:  47
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        INIT_METHOD_CALL                                         !1, 'modify'
         10        SEND_VAL_EX                                              '%2B1+day'
         11        DO_FCALL                                      0  $11     
         12        SEND_VAR_NO_REF_EX                                       $11
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !3, $8
    6    15      > FE_RESET_R                                       $14     !3, ->44
         16    > > FE_FETCH_R                                               $14, !4, ->44
    7    17    >   INIT_METHOD_CALL                                         !4, 'format'
         18        SEND_VAL_EX                                              'w'
         19        DO_FCALL                                      0  $15     
         20        CAST                                          4  ~16     $15
         21        ASSIGN                                                   !5, ~16
    8    22        INIT_METHOD_CALL                                         !4, 'format'
         23        SEND_VAL_EX                                              'j'
         24        DO_FCALL                                      0  $18     
         25        CAST                                          4  ~19     $18
         26        ASSIGN                                                   !6, ~19
    9    27        IS_SMALLER_OR_EQUAL                              ~21     1, !5
         28      > JMPZ_EX                                          ~21     ~21, ->31
         29    >   IS_SMALLER_OR_EQUAL                              ~22     !5, 5
         30        BOOL                                             ~21     ~22
         31    > > JMPZ                                                     ~21, ->35
   10    32    >   ASSIGN_DIM                                               !2
         33        OP_DATA                                                  !4
    9    34      > JMP                                                      ->43
   11    35    >   IS_EQUAL                                         ~24     !5, 6
         36      > JMPZ_EX                                          ~24     ~24, ->40
         37    >   MOD                                              ~25     !6, 2
         38        IS_EQUAL                                         ~26     ~25, 0
         39        BOOL                                             ~24     ~26
         40    > > JMPZ                                                     ~24, ->43
   12    41    >   ASSIGN_DIM                                               !2
         42        OP_DATA                                                  !4
    6    43    > > JMP                                                      ->16
         44    >   FE_FREE                                                  $14
   15    45      > RETURN                                                   !2
   16    46*     > RETURN                                                   null

End of function work_days_between_two_dates

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.18 ms | 1457 KiB | 14 Q