3v4l.org

run code in 300+ PHP versions simultaneously
<?php function reduceOverlap(array $arr){ $flag = true; while($flag){ $flag = false; foreach($arr as $key1 => $row1){ foreach($arr as $key2 => $row2){ if($key1 === $key2) continue; if(($row1['open'] >= $row2['open'] && $row1['open'] <= $row2['close']) OR ($row1['close'] >= $row2['open'] && $row1['close'] <= $row2['close'])){ $arr[$key1]['open'] = min($row1['open'],$row2['open']); $arr[$key1]['close'] = max($row1['close'],$row2['close']); unset($arr[$key2]); $flag = true; break 2; } } } } return $arr; } function diffTotal(array $arr){ $date = date_create('1970-01-01 00:00'); foreach($arr as $row){ $diff = date_create($row['open'])->diff(date_create($row['close'])); $date->add($diff); } return date_create('1970-01-01 00:00')->diff($date); } $times = [ ['open' => '2023-01-02 09:00:00', 'close' => '2023-01-02 14:00:00'], ['open' => '2023-01-02 11:00:00', 'close' => '2023-01-02 15:00:00'], ['open' => '2023-01-14 10:00:00', 'close' => '2023-01-14 11:00:00'], ]; $arr = reduceOverlap($times); $diffTotal = diffTotal($arr); var_dump($diffTotal);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MPNPC
function name:  (null)
number of ops:  13
compiled vars:  !0 = $times, !1 = $arr, !2 = $diffTotal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN                                                   !0, <array>
   40     1        INIT_FCALL                                               'reduceoverlap'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   42     5        INIT_FCALL                                               'difftotal'
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !2, $6
   44     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function reduceoverlap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 3
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 57
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 57
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 55
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 55
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
2 jumps found. (Code = 47) Position 1 = 22, Position 2 = 31
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 54
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 3
Branch analysis from position: 59
Branch analysis from position: 3
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 30
Branch analysis from position: 31
Branch analysis from position: 21
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 55
Branch analysis from position: 57
Branch analysis from position: 57
filename:       /in/MPNPC
function name:  reduceOverlap
number of ops:  61
compiled vars:  !0 = $arr, !1 = $flag, !2 = $row1, !3 = $key1, !4 = $row2, !5 = $key2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <true>
    5     2      > JMP                                                      ->58
    6     3    >   ASSIGN                                                   !1, <false>
    7     4      > FE_RESET_R                                       $8      !0, ->57
          5    > > FE_FETCH_R                                       ~9      $8, !2, ->57
          6    >   ASSIGN                                                   !3, ~9
    8     7      > FE_RESET_R                                       $11     !0, ->55
          8    > > FE_FETCH_R                                       ~12     $11, !4, ->55
          9    >   ASSIGN                                                   !5, ~12
    9    10        IS_IDENTICAL                                             !3, !5
         11      > JMPZ                                                     ~14, ->13
         12    > > JMP                                                      ->8
   10    13    >   FETCH_DIM_R                                      ~15     !2, 'open'
         14        FETCH_DIM_R                                      ~16     !4, 'open'
         15        IS_SMALLER_OR_EQUAL                              ~17     ~16, ~15
         16      > JMPZ_EX                                          ~17     ~17, ->21
         17    >   FETCH_DIM_R                                      ~18     !2, 'open'
         18        FETCH_DIM_R                                      ~19     !4, 'close'
         19        IS_SMALLER_OR_EQUAL                              ~20     ~18, ~19
         20        BOOL                                             ~17     ~20
         21    > > JMPNZ_EX                                         ~17     ~17, ->31
   11    22    >   FETCH_DIM_R                                      ~21     !2, 'close'
         23        FETCH_DIM_R                                      ~22     !4, 'open'
         24        IS_SMALLER_OR_EQUAL                              ~23     ~22, ~21
         25      > JMPZ_EX                                          ~23     ~23, ->30
         26    >   FETCH_DIM_R                                      ~24     !2, 'close'
         27        FETCH_DIM_R                                      ~25     !4, 'close'
         28        IS_SMALLER_OR_EQUAL                              ~26     ~24, ~25
         29        BOOL                                             ~23     ~26
         30    >   BOOL                                             ~17     ~23
         31    > > JMPZ                                                     ~17, ->54
   12    32    >   INIT_FCALL                                               'min'
         33        FETCH_DIM_R                                      ~29     !2, 'open'
         34        SEND_VAL                                                 ~29
         35        FETCH_DIM_R                                      ~30     !4, 'open'
         36        SEND_VAL                                                 ~30
         37        DO_ICALL                                         $31     
         38        FETCH_DIM_W                                      $27     !0, !3
         39        ASSIGN_DIM                                               $27, 'open'
         40        OP_DATA                                                  $31
   13    41        INIT_FCALL                                               'max'
         42        FETCH_DIM_R                                      ~34     !2, 'close'
         43        SEND_VAL                                                 ~34
         44        FETCH_DIM_R                                      ~35     !4, 'close'
         45        SEND_VAL                                                 ~35
         46        DO_ICALL                                         $36     
         47        FETCH_DIM_W                                      $32     !0, !3
         48        ASSIGN_DIM                                               $32, 'close'
         49        OP_DATA                                                  $36
   14    50        UNSET_DIM                                                !0, !5
   15    51        ASSIGN                                                   !1, <true>
   16    52        FE_FREE                                                  $11
         53      > JMP                                                      ->57
    8    54    > > JMP                                                      ->8
         55    >   FE_FREE                                                  $11
    7    56      > JMP                                                      ->5
         57    >   FE_FREE                                                  $8
    5    58    > > JMPNZ                                                    !1, ->3
   21    59    > > RETURN                                                   !0
   22    60*     > RETURN                                                   null

End of function reduceoverlap

Function difftotal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 23
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 23
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/MPNPC
function name:  diffTotal
number of ops:  32
compiled vars:  !0 = $arr, !1 = $date, !2 = $row, !3 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'date_create'
          2        SEND_VAL                                                 '1970-01-01+00%3A00'
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   26     5      > FE_RESET_R                                       $6      !0, ->23
          6    > > FE_FETCH_R                                               $6, !2, ->23
   27     7    >   INIT_FCALL                                               'date_create'
          8        FETCH_DIM_R                                      ~7      !2, 'open'
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                         $8      
         11        INIT_METHOD_CALL                                         $8, 'diff'
         12        INIT_FCALL                                               'date_create'
         13        FETCH_DIM_R                                      ~9      !2, 'close'
         14        SEND_VAL                                                 ~9
         15        DO_ICALL                                         $10     
         16        SEND_VAR_NO_REF_EX                                       $10
         17        DO_FCALL                                      0  $11     
         18        ASSIGN                                                   !3, $11
   28    19        INIT_METHOD_CALL                                         !1, 'add'
         20        SEND_VAR_EX                                              !3
         21        DO_FCALL                                      0          
   26    22      > JMP                                                      ->6
         23    >   FE_FREE                                                  $6
   30    24        INIT_FCALL                                               'date_create'
         25        SEND_VAL                                                 '1970-01-01+00%3A00'
         26        DO_ICALL                                         $14     
         27        INIT_METHOD_CALL                                         $14, 'diff'
         28        SEND_VAR_EX                                              !1
         29        DO_FCALL                                      0  $15     
         30      > RETURN                                                   $15
   31    31*     > RETURN                                                   null

End of function difftotal

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.53 ms | 1016 KiB | 19 Q