3v4l.org

run code in 500+ PHP versions simultaneously
<?php function removeDuplicates($array){ $freq = 5; $result = []; $size = count($array); $counts = []; for($i=0;$i<$size;++$i) $counts[] = 0; $counts[$size-1] = 1; for($i=$size-2;$i>=0;--$i){ $counts[$i] = 1; if($array[$i] === $array[$i+1]) $counts[$i] = $counts[$i+1] + 1; } for($i=0;$i<$size;++$i){ $result[] = $array[$i]; if($counts[$i] >= $freq){ $i += $counts[$i] - 1; } } return $result; } $array = array(1,2,4,1,1,1,1,0,8,7,2,0,0,8,8,8,8,8,8,8,2,4,1,5); print_r(removeDuplicates($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mvjOq
function name:  (null)
number of ops:  8
compiled vars:  !0 = $array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   ASSIGN                                                       !0, <array>
   31     1        INIT_FCALL                                                   'print_r'
          2        INIT_FCALL                                                   'removeduplicates'
          3        SEND_VAR                                                     !0
          4        DO_FCALL                                          0  $2      
          5        SEND_VAR                                                     $2
          6        DO_ICALL                                                     
          7      > RETURN                                                       1

Function removeduplicates:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 19
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 36
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 36
Branch analysis from position: 48
Branch analysis from position: 36
Branch analysis from position: 45
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 19
Branch analysis from position: 34
Branch analysis from position: 19
Branch analysis from position: 31
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
Branch analysis from position: 8
filename:       /in/mvjOq
function name:  removeDuplicates
number of ops:  50
compiled vars:  !0 = $array, !1 = $freq, !2 = $result, !3 = $size, !4 = $counts, !5 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        ASSIGN                                                       !1, 5
    6     2        ASSIGN                                                       !2, <array>
    7     3        COUNT                                                ~8      !0
          4        ASSIGN                                                       !3, ~8
    9     5        ASSIGN                                                       !4, <array>
   10     6        ASSIGN                                                       !5, 0
          7      > JMP                                                          ->11
          8    >   ASSIGN_DIM                                                   !4
          9        OP_DATA                                                      0
         10        PRE_INC                                                      !5
         11    >   IS_SMALLER                                                   !5, !3
         12      > JMPNZ                                                        ~14, ->8
   12    13    >   SUB                                                  ~15     !3, 1
         14        ASSIGN_DIM                                                   !4, ~15
         15        OP_DATA                                                      1
   14    16        SUB                                                  ~17     !3, 2
         17        ASSIGN                                                       !5, ~17
         18      > JMP                                                          ->32
   15    19    >   ASSIGN_DIM                                                   !4, !5
         20        OP_DATA                                                      1
   16    21        FETCH_DIM_R                                          ~20     !0, !5
         22        ADD                                                  ~21     !5, 1
         23        FETCH_DIM_R                                          ~22     !0, ~21
         24        IS_IDENTICAL                                                 ~20, ~22
         25      > JMPZ                                                         ~23, ->31
         26    >   ADD                                                  ~25     !5, 1
         27        FETCH_DIM_R                                          ~26     !4, ~25
         28        ADD                                                  ~27     ~26, 1
         29        ASSIGN_DIM                                                   !4, !5
         30        OP_DATA                                                      ~27
   14    31    >   PRE_DEC                                                      !5
         32    >   IS_SMALLER_OR_EQUAL                                          0, !5
         33      > JMPNZ                                                        ~29, ->19
   19    34    >   ASSIGN                                                       !5, 0
         35      > JMP                                                          ->46
   20    36    >   FETCH_DIM_R                                          ~32     !0, !5
         37        ASSIGN_DIM                                                   !2
         38        OP_DATA                                                      ~32
   21    39        FETCH_DIM_R                                          ~33     !4, !5
         40        IS_SMALLER_OR_EQUAL                                          !1, ~33
         41      > JMPZ                                                         ~34, ->45
   22    42    >   FETCH_DIM_R                                          ~35     !4, !5
         43        SUB                                                  ~36     ~35, 1
         44        ASSIGN_OP                                         1          !5, ~36
   19    45    >   PRE_INC                                                      !5
         46    >   IS_SMALLER                                                   !5, !3
         47      > JMPNZ                                                        ~39, ->36
   26    48    > > RETURN                                                       !2
   27    49*     > RETURN                                                       null

End of function removeduplicates

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.04 ms | 2228 KiB | 15 Q