3v4l.org

run code in 300+ PHP versions simultaneously
<?php $intervals = [ [1, 2], [2, 2], [5, 6], [8, 10], ]; $rr = []; foreach($intervals as $v){ $rr[] = range($v[0],$v[1]); } $n = 10; $range = range(1,$n); $diff = array_diff($range,array_values(array_unique(array_merge(...$rr)))); $r = groupConsecutive($diff); echo '<pre>'; print_r($r); function groupConsecutive($array) { $ret = array(); $temp = array(); foreach($array as $val) { if(next($array) == ($val + 1)) $temp[] = $val; else if(count($temp) > 0) { $temp[] = $val; $ret[] = $temp; $temp = array(); } else $ret[] = $val; } return $ret; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/7G4UF
function name:  (null)
number of ops:  44
compiled vars:  !0 = $intervals, !1 = $rr, !2 = $v, !3 = $n, !4 = $range, !5 = $diff, !6 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $9      !0, ->13
          3    > > FE_FETCH_R                                               $9, !2, ->13
   12     4    >   INIT_FCALL                                               'range'
          5        FETCH_DIM_R                                      ~11     !2, 0
          6        SEND_VAL                                                 ~11
          7        FETCH_DIM_R                                      ~12     !2, 1
          8        SEND_VAL                                                 ~12
          9        DO_ICALL                                         $13     
         10        ASSIGN_DIM                                               !1
         11        OP_DATA                                                  $13
   11    12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $9
   14    14        ASSIGN                                                   !3, 10
   15    15        INIT_FCALL                                               'range'
         16        SEND_VAL                                                 1
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $15     
         19        ASSIGN                                                   !4, $15
   16    20        INIT_FCALL                                               'array_diff'
         21        SEND_VAR                                                 !4
         22        INIT_FCALL                                               'array_values'
         23        INIT_FCALL                                               'array_unique'
         24        INIT_FCALL                                               'array_merge'
         25        SEND_UNPACK                                              !1
         26        CHECK_UNDEF_ARGS                                         
         27        DO_ICALL                                         $17     
         28        SEND_VAR                                                 $17
         29        DO_ICALL                                         $18     
         30        SEND_VAR                                                 $18
         31        DO_ICALL                                         $19     
         32        SEND_VAR                                                 $19
         33        DO_ICALL                                         $20     
         34        ASSIGN                                                   !5, $20
   17    35        INIT_FCALL_BY_NAME                                       'groupConsecutive'
         36        SEND_VAR_EX                                              !5
         37        DO_FCALL                                      0  $22     
         38        ASSIGN                                                   !6, $22
   19    39        ECHO                                                     '%3Cpre%3E'
   20    40        INIT_FCALL                                               'print_r'
         41        SEND_VAR                                                 !6
         42        DO_ICALL                                                 
   38    43      > RETURN                                                   1

Function groupconsecutive:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 26
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/7G4UF
function name:  groupConsecutive
number of ops:  29
compiled vars:  !0 = $array, !1 = $ret, !2 = $temp, !3 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        ASSIGN                                                   !1, <array>
   24     2        ASSIGN                                                   !2, <array>
   25     3      > FE_RESET_R                                       $6      !0, ->26
          4    > > FE_FETCH_R                                               $6, !3, ->26
   26     5    >   INIT_FCALL                                               'next'
          6        SEND_REF                                                 !0
          7        DO_ICALL                                         $7      
          8        ADD                                              ~8      !3, 1
          9        IS_EQUAL                                                 $7, ~8
         10      > JMPZ                                                     ~9, ->14
   27    11    >   ASSIGN_DIM                                               !2
         12        OP_DATA                                                  !3
   26    13      > JMP                                                      ->25
   29    14    >   COUNT                                            ~11     !2
         15        IS_SMALLER                                               0, ~11
         16      > JMPZ                                                     ~12, ->23
   30    17    >   ASSIGN_DIM                                               !2
         18        OP_DATA                                                  !3
   31    19        ASSIGN_DIM                                               !1
         20        OP_DATA                                                  !2
   32    21        ASSIGN                                                   !2, <array>
   29    22      > JMP                                                      ->25
   35    23    >   ASSIGN_DIM                                               !1
         24        OP_DATA                                                  !3
   25    25    > > JMP                                                      ->4
         26    >   FE_FREE                                                  $6
   37    27      > RETURN                                                   !1
   38    28*     > RETURN                                                   null

End of function groupconsecutive

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
294.93 ms | 1022 KiB | 20 Q