3v4l.org

run code in 300+ PHP versions simultaneously
<?php $hours = ["08:00:00", "18:00:00"]; $bookings = [["10:00:00", "15:00:00"], ["08:05:00", "09:00:00"], ["16:00:00", "17:00:00"] ]; $start = $hours[0]; $end = $hours[1]; // sort the bookings $bstart = array_column($bookings, 0); array_multisort($bstart, $bookings); // get the free times $time = $start; $bindex = 0; $free = array(); while ($time < $end && $bindex < count($bookings)) { if ($time < $bookings[$bindex][0]) { $free[] = [$time, $bookings[$bindex][0]]; } $time = $bookings[$bindex][1]; $bindex++; } // end of day free? if ($time < $end) { $free[] = [$time, $end]; } print_r($free);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 19
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
Branch analysis from position: 38
Branch analysis from position: 29
Branch analysis from position: 38
filename:       /in/CB0S0
function name:  (null)
number of ops:  49
compiled vars:  !0 = $hours, !1 = $bookings, !2 = $start, !3 = $end, !4 = $bstart, !5 = $time, !6 = $bindex, !7 = $free
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
   10     2        FETCH_DIM_R                                      ~10     !0, 0
          3        ASSIGN                                                   !2, ~10
   11     4        FETCH_DIM_R                                      ~12     !0, 1
          5        ASSIGN                                                   !3, ~12
   14     6        INIT_FCALL                                               'array_column'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 0
          9        DO_ICALL                                         $14     
         10        ASSIGN                                                   !4, $14
   15    11        INIT_FCALL                                               'array_multisort'
         12        SEND_REF                                                 !4
         13        SEND_REF                                                 !1
         14        DO_ICALL                                                 
   18    15        ASSIGN                                                   !5, !2
   19    16        ASSIGN                                                   !6, 0
   20    17        ASSIGN                                                   !7, <array>
   21    18      > JMP                                                      ->33
   22    19    >   FETCH_DIM_R                                      ~20     !1, !6
         20        FETCH_DIM_R                                      ~21     ~20, 0
         21        IS_SMALLER                                               !5, ~21
         22      > JMPZ                                                     ~22, ->29
   23    23    >   INIT_ARRAY                                       ~24     !5
         24        FETCH_DIM_R                                      ~25     !1, !6
         25        FETCH_DIM_R                                      ~26     ~25, 0
         26        ADD_ARRAY_ELEMENT                                ~24     ~26
         27        ASSIGN_DIM                                               !7
         28        OP_DATA                                                  ~24
   25    29    >   FETCH_DIM_R                                      ~27     !1, !6
         30        FETCH_DIM_R                                      ~28     ~27, 1
         31        ASSIGN                                                   !5, ~28
   26    32        PRE_INC                                                  !6
   21    33    >   IS_SMALLER                                       ~31     !5, !3
         34      > JMPZ_EX                                          ~31     ~31, ->38
         35    >   COUNT                                            ~32     !1
         36        IS_SMALLER                                       ~33     !6, ~32
         37        BOOL                                             ~31     ~33
         38    > > JMPNZ                                                    ~31, ->19
   29    39    >   IS_SMALLER                                               !5, !3
         40      > JMPZ                                                     ~34, ->45
   30    41    >   INIT_ARRAY                                       ~36     !5
         42        ADD_ARRAY_ELEMENT                                ~36     !3
         43        ASSIGN_DIM                                               !7
         44        OP_DATA                                                  ~36
   32    45    >   INIT_FCALL                                               'print_r'
         46        SEND_VAR                                                 !7
         47        DO_ICALL                                                 
         48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.98 ms | 1400 KiB | 19 Q