3v4l.org

run code in 300+ PHP versions simultaneously
<?php $intervals = [ ['from_time' => '15:00', 'to_time' => '17:15'], ['from_time' => '10:00', 'to_time' => '12:15'], ['from_time' => '09:00', 'to_time' => '11:15'], ['from_time' => '09:00', 'to_time' => '11:15'], ['from_time' => '14:00', 'to_time' => '16:15'], ['from_time' => '15:00', 'to_time' => '17:15'], ]; $overlaps = []; foreach ($intervals as $interval) { $key = null; foreach ($overlaps as $_key => $_intervals) { foreach ($_intervals as $_interval) { if ( ($_interval['from_time'] <= $interval['from_time'] && $interval['from_time'] <= $_interval['to_time']) || ($_interval['from_time'] <= $interval['to_time'] && $interval['to_time'] <= $_interval['to_time']) ) { $key = $_key; break 2; } } } if (is_null($key)) { $key = count($overlaps); } $overlaps[$key][] = $interval; } foreach ($overlaps as &$overlap) { $from = '00:00'; $to = '23:59'; foreach ($overlap as $_interval) { $from = max($from, $_interval['from_time']); $to = min($to, $_interval['to_time']); } $overlap = ['from_time' => $from, 'to_time' => $to]; } unset($overlap); print_r($overlaps);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 44
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 44
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 35
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 35
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 33
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 33
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
2 jumps found. (Code = 47) Position 1 = 19, Position 2 = 28
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 40
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 27
Branch analysis from position: 28
Branch analysis from position: 18
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 33
Branch analysis from position: 35
Branch analysis from position: 35
Branch analysis from position: 44
2 jumps found. (Code = 125) Position 1 = 46, Position 2 = 69
Branch analysis from position: 46
2 jumps found. (Code = 126) Position 1 = 47, Position 2 = 69
Branch analysis from position: 47
2 jumps found. (Code = 77) Position 1 = 50, Position 2 = 64
Branch analysis from position: 50
2 jumps found. (Code = 78) Position 1 = 51, Position 2 = 64
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 64
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
Branch analysis from position: 44
filename:       /in/hg0tu
function name:  (null)
number of ops:  75
compiled vars:  !0 = $intervals, !1 = $overlaps, !2 = $interval, !3 = $key, !4 = $_intervals, !5 = $_key, !6 = $_interval, !7 = $overlap, !8 = $from, !9 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   12     1        ASSIGN                                                   !1, <array>
   14     2      > FE_RESET_R                                       $12     !0, ->44
          3    > > FE_FETCH_R                                               $12, !2, ->44
   15     4    >   ASSIGN                                                   !3, null
   16     5      > FE_RESET_R                                       $14     !1, ->35
          6    > > FE_FETCH_R                                       ~15     $14, !4, ->35
          7    >   ASSIGN                                                   !5, ~15
   17     8      > FE_RESET_R                                       $17     !4, ->33
          9    > > FE_FETCH_R                                               $17, !6, ->33
   19    10    >   FETCH_DIM_R                                      ~18     !6, 'from_time'
         11        FETCH_DIM_R                                      ~19     !2, 'from_time'
         12        IS_SMALLER_OR_EQUAL                              ~20     ~18, ~19
         13      > JMPZ_EX                                          ~20     ~20, ->18
         14    >   FETCH_DIM_R                                      ~21     !2, 'from_time'
         15        FETCH_DIM_R                                      ~22     !6, 'to_time'
         16        IS_SMALLER_OR_EQUAL                              ~23     ~21, ~22
         17        BOOL                                             ~20     ~23
         18    > > JMPNZ_EX                                         ~20     ~20, ->28
   21    19    >   FETCH_DIM_R                                      ~24     !6, 'from_time'
         20        FETCH_DIM_R                                      ~25     !2, 'to_time'
         21        IS_SMALLER_OR_EQUAL                              ~26     ~24, ~25
         22      > JMPZ_EX                                          ~26     ~26, ->27
         23    >   FETCH_DIM_R                                      ~27     !2, 'to_time'
         24        FETCH_DIM_R                                      ~28     !6, 'to_time'
         25        IS_SMALLER_OR_EQUAL                              ~29     ~27, ~28
         26        BOOL                                             ~26     ~29
         27    >   BOOL                                             ~20     ~26
         28    > > JMPZ                                                     ~20, ->32
   23    29    >   ASSIGN                                                   !3, !5
   24    30        FE_FREE                                                  $17
         31      > JMP                                                      ->35
   17    32    > > JMP                                                      ->9
         33    >   FE_FREE                                                  $17
   16    34      > JMP                                                      ->6
         35    >   FE_FREE                                                  $14
   28    36        TYPE_CHECK                                    2          !3
         37      > JMPZ                                                     ~31, ->40
   29    38    >   COUNT                                            ~32     !1
         39        ASSIGN                                                   !3, ~32
   31    40    >   FETCH_DIM_W                                      $34     !1, !3
         41        ASSIGN_DIM                                               $34
         42        OP_DATA                                                  !2
   14    43      > JMP                                                      ->3
         44    >   FE_FREE                                                  $12
   33    45      > FE_RESET_RW                                      $36     !1, ->69
         46    > > FE_FETCH_RW                                              $36, !7, ->69
   34    47    >   ASSIGN                                                   !8, '00%3A00'
   35    48        ASSIGN                                                   !9, '23%3A59'
   36    49      > FE_RESET_R                                       $39     !7, ->64
         50    > > FE_FETCH_R                                               $39, !6, ->64
   37    51    >   INIT_FCALL                                               'max'
         52        SEND_VAR                                                 !8
         53        FETCH_DIM_R                                      ~40     !6, 'from_time'
         54        SEND_VAL                                                 ~40
         55        DO_ICALL                                         $41     
         56        ASSIGN                                                   !8, $41
   38    57        INIT_FCALL                                               'min'
         58        SEND_VAR                                                 !9
         59        FETCH_DIM_R                                      ~43     !6, 'to_time'
         60        SEND_VAL                                                 ~43
         61        DO_ICALL                                         $44     
         62        ASSIGN                                                   !9, $44
   36    63      > JMP                                                      ->50
         64    >   FE_FREE                                                  $39
   40    65        INIT_ARRAY                                       ~46     !8, 'from_time'
         66        ADD_ARRAY_ELEMENT                                ~46     !9, 'to_time'
         67        ASSIGN                                                   !7, ~46
   33    68      > JMP                                                      ->46
         69    >   FE_FREE                                                  $36
   42    70        UNSET_CV                                                 !7
   44    71        INIT_FCALL                                               'print_r'
         72        SEND_VAR                                                 !1
         73        DO_ICALL                                                 
         74      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.01 ms | 1444 KiB | 16 Q