3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isWeekend($date) { return $date->format('N') >= 6; } function getDayOffInDaysOffByDate($daysOff, \DateTime $date) { $dayOffInDate = null; foreach ($daysOff as $dayOff) { if ($dayOff->getDate()->format('Y-m-d') == $date->format('Y-m-d')) { $dayOffInDate = $dayOff; } } return $dayOffInDate; } $daysOff = array(new \DateTime('2017-07-03'), new \DateTime('2017-07-04')); $periodStartDate = new \DateTime('today'); $periodStartDate = $periodStartDate->modify('-5 days'); $periodEndDate = new \DateTime('today'); $periodEndDate->modify('+1 day'); $period = new \DatePeriod($periodStartDate, \DateInterval::createFromDateString('1 day'), $periodEndDate); foreach ($period as $date) { echo $date->format('Y-m-d'); echo('\n'); if (getDayOffInDaysOffByDate($daysOff, $date) || isWeekend($date)) { echo('minus'); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 34, Position 2 = 52
Branch analysis from position: 34
2 jumps found. (Code = 78) Position 1 = 35, Position 2 = 52
Branch analysis from position: 35
2 jumps found. (Code = 47) Position 1 = 45, Position 2 = 49
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 51
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 51
Branch analysis from position: 49
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/dGYeI
function name:  (null)
number of ops:  54
compiled vars:  !0 = $daysOff, !1 = $periodStartDate, !2 = $periodEndDate, !3 = $period, !4 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                                              $5      'DateTime'
          1        SEND_VAL_EX                                              '2017-07-03'
          2        DO_FCALL                                      0          
          3        INIT_ARRAY                                       ~7      $5
          4        NEW                                              $8      'DateTime'
          5        SEND_VAL_EX                                              '2017-07-04'
          6        DO_FCALL                                      0          
          7        ADD_ARRAY_ELEMENT                                ~7      $8
          8        ASSIGN                                                   !0, ~7
   21     9        NEW                                              $11     'DateTime'
         10        SEND_VAL_EX                                              'today'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $11
   22    13        INIT_METHOD_CALL                                         !1, 'modify'
         14        SEND_VAL_EX                                              '-5+days'
         15        DO_FCALL                                      0  $14     
         16        ASSIGN                                                   !1, $14
   23    17        NEW                                              $16     'DateTime'
         18        SEND_VAL_EX                                              'today'
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !2, $16
   24    21        INIT_METHOD_CALL                                         !2, 'modify'
         22        SEND_VAL_EX                                              '%2B1+day'
         23        DO_FCALL                                      0          
   25    24        NEW                                              $20     'DatePeriod'
         25        SEND_VAR_EX                                              !1
         26        INIT_STATIC_METHOD_CALL                                  'DateInterval', 'createFromDateString'
         27        SEND_VAL                                                 '1+day'
         28        DO_FCALL                                      0  $21     
         29        SEND_VAR_NO_REF_EX                                       $21
         30        SEND_VAR_EX                                              !2
         31        DO_FCALL                                      0          
         32        ASSIGN                                                   !3, $20
   27    33      > FE_RESET_R                                       $24     !3, ->52
         34    > > FE_FETCH_R                                               $24, !4, ->52
   28    35    >   INIT_METHOD_CALL                                         !4, 'format'
         36        SEND_VAL_EX                                              'Y-m-d'
         37        DO_FCALL                                      0  $25     
         38        ECHO                                                     $25
   29    39        ECHO                                                     '%5Cn'
   30    40        INIT_FCALL                                               'getdayoffindaysoffbydate'
         41        SEND_VAR                                                 !0
         42        SEND_VAR                                                 !4
         43        DO_FCALL                                      0  $26     
         44      > JMPNZ_EX                                         ~27     $26, ->49
         45    >   INIT_FCALL                                               'isweekend'
         46        SEND_VAR                                                 !4
         47        DO_FCALL                                      0  $28     
         48        BOOL                                             ~27     $28
         49    > > JMPZ                                                     ~27, ->51
   31    50    >   ECHO                                                     'minus'
   27    51    > > JMP                                                      ->34
         52    >   FE_FREE                                                  $24
   33    53      > RETURN                                                   1

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

End of function isweekend

Function getdayoffindaysoffbydate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 17
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 16
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/dGYeI
function name:  getDayOffInDaysOffByDate
number of ops:  20
compiled vars:  !0 = $daysOff, !1 = $date, !2 = $dayOffInDate, !3 = $dayOff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        ASSIGN                                                   !2, null
   11     3      > FE_RESET_R                                       $5      !0, ->17
          4    > > FE_FETCH_R                                               $5, !3, ->17
   12     5    >   INIT_METHOD_CALL                                         !3, 'getDate'
          6        DO_FCALL                                      0  $6      
          7        INIT_METHOD_CALL                                         $6, 'format'
          8        SEND_VAL_EX                                              'Y-m-d'
          9        DO_FCALL                                      0  $7      
         10        INIT_METHOD_CALL                                         !1, 'format'
         11        SEND_VAL_EX                                              'Y-m-d'
         12        DO_FCALL                                      0  $8      
         13        IS_EQUAL                                                 $7, $8
         14      > JMPZ                                                     ~9, ->16
   13    15    >   ASSIGN                                                   !2, !3
   11    16    > > JMP                                                      ->4
         17    >   FE_FREE                                                  $5
   17    18      > RETURN                                                   !2
   18    19*     > RETURN                                                   null

End of function getdayoffindaysoffbydate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.43 ms | 1407 KiB | 15 Q