3v4l.org

run code in 300+ PHP versions simultaneously
<?php $appointments = array( array( 'start_date' => '2018-04-02 12:00:00', 'end_date' => '2018-04-02 12:55:00' ), array( 'start_date' => '2018-04-02 13:00:00', 'end_date' => '2018-04-02 13:55:00' ) ); $begin = new DateTime('2018-04-02 09:00:00'); $end = new DateTime('2018-04-02 18:30:00'); $interval = new DateInterval('PT5M'); $daterange = new DatePeriod($begin, $interval ,$end); $availableDates = []; foreach($daterange as $date) { $availableDates[] = $date; } foreach($appointments as $appointment) { $startsAt = new DateTime($appointment['start_date']); $endsAt = new DateTime($appointment['end_date']); foreach ($availableDates as $key => $date) { if ($startsAt <= $date && $endsAt >= $date) { unset($availableDates[$key]); } } } foreach($availableDates as $date){ echo $date->format("Y-m-d H:i:s") . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 52
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 52
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 50
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 50
Branch analysis from position: 42
2 jumps found. (Code = 46) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 49
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 49
Branch analysis from position: 47
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 50
Branch analysis from position: 52
2 jumps found. (Code = 77) Position 1 = 54, Position 2 = 61
Branch analysis from position: 54
2 jumps found. (Code = 78) Position 1 = 55, Position 2 = 61
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
Branch analysis from position: 52
Branch analysis from position: 25
filename:       /in/6pNBX
function name:  (null)
number of ops:  63
compiled vars:  !0 = $appointments, !1 = $begin, !2 = $end, !3 = $interval, !4 = $daterange, !5 = $availableDates, !6 = $date, !7 = $appointment, !8 = $startsAt, !9 = $endsAt, !10 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        NEW                                              $12     'DateTime'
          2        SEND_VAL_EX                                              '2018-04-02+09%3A00%3A00'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $12
   15     5        NEW                                              $15     'DateTime'
          6        SEND_VAL_EX                                              '2018-04-02+18%3A30%3A00'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $15
   17     9        NEW                                              $18     'DateInterval'
         10        SEND_VAL_EX                                              'PT5M'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !3, $18
   18    13        NEW                                              $21     'DatePeriod'
         14        SEND_VAR_EX                                              !1
         15        SEND_VAR_EX                                              !3
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !4, $21
   20    19        ASSIGN                                                   !5, <array>
   21    20      > FE_RESET_R                                       $25     !4, ->25
         21    > > FE_FETCH_R                                               $25, !6, ->25
   22    22    >   ASSIGN_DIM                                               !5
         23        OP_DATA                                                  !6
   21    24      > JMP                                                      ->21
         25    >   FE_FREE                                                  $25
   25    26      > FE_RESET_R                                       $27     !0, ->52
         27    > > FE_FETCH_R                                               $27, !7, ->52
   26    28    >   NEW                                              $28     'DateTime'
         29        CHECK_FUNC_ARG                                           
         30        FETCH_DIM_FUNC_ARG                               $29     !7, 'start_date'
         31        SEND_FUNC_ARG                                            $29
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !8, $28
   27    34        NEW                                              $32     'DateTime'
         35        CHECK_FUNC_ARG                                           
         36        FETCH_DIM_FUNC_ARG                               $33     !7, 'end_date'
         37        SEND_FUNC_ARG                                            $33
         38        DO_FCALL                                      0          
         39        ASSIGN                                                   !9, $32
   28    40      > FE_RESET_R                                       $36     !5, ->50
         41    > > FE_FETCH_R                                       ~37     $36, !6, ->50
         42    >   ASSIGN                                                   !10, ~37
   29    43        IS_SMALLER_OR_EQUAL                              ~39     !8, !6
         44      > JMPZ_EX                                          ~39     ~39, ->47
         45    >   IS_SMALLER_OR_EQUAL                              ~40     !6, !9
         46        BOOL                                             ~39     ~40
         47    > > JMPZ                                                     ~39, ->49
   30    48    >   UNSET_DIM                                                !5, !10
   28    49    > > JMP                                                      ->41
         50    >   FE_FREE                                                  $36
   25    51      > JMP                                                      ->27
         52    >   FE_FREE                                                  $27
   35    53      > FE_RESET_R                                       $41     !5, ->61
         54    > > FE_FETCH_R                                               $41, !6, ->61
   36    55    >   INIT_METHOD_CALL                                         !6, 'format'
         56        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         57        DO_FCALL                                      0  $42     
         58        CONCAT                                           ~43     $42, '%0A'
         59        ECHO                                                     ~43
   35    60      > JMP                                                      ->54
         61    >   FE_FREE                                                  $41
   37    62      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
240.91 ms | 1004 KiB | 13 Q