3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array('title1','title2','title2','title3','title4','title5','title5','title6','title6','title5'); sort($array); $unique_length = count( array_unique($array) ); $total_dupes = 0; $clean = array(); for ($i=0; $i<$unique_length; $i++) { $current = array_shift($array); if ($current === NULL)//already have all elements break; $found = 1; while (($key = array_search($current, $array)) !== FALSE) {//search for dupes $found++; unset($array[$key]); } if ($found == 1) array_push($clean, $current); else { $dupes = array(); for ($i=0; $i<$found; $i++) $dupes[] = $current; $total_dupes++; $clean['dupe'.$total_dupes] = $dupes; } } print_r($array); print_r($clean);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 13
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 22
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 38
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 13
Branch analysis from position: 53
Branch analysis from position: 13
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 41
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 13
Branch analysis from position: 53
Branch analysis from position: 13
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 41
Branch analysis from position: 46
Branch analysis from position: 41
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 22
Branch analysis from position: 31
Branch analysis from position: 22
filename:       /in/AIDeF
function name:  (null)
number of ops:  60
compiled vars:  !0 = $array, !1 = $unique_length, !2 = $total_dupes, !3 = $clean, !4 = $i, !5 = $current, !6 = $found, !7 = $key, !8 = $dupes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        INIT_FCALL                                               'sort'
          2        SEND_REF                                                 !0
          3        DO_ICALL                                                 
    6     4        INIT_FCALL                                               'array_unique'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $11     
          7        COUNT                                            ~12     $11
          8        ASSIGN                                                   !1, ~12
    7     9        ASSIGN                                                   !2, 0
    9    10        ASSIGN                                                   !3, <array>
   11    11        ASSIGN                                                   !4, 0
         12      > JMP                                                      ->51
   12    13    >   INIT_FCALL                                               'array_shift'
         14        SEND_REF                                                 !0
         15        DO_ICALL                                         $17     
         16        ASSIGN                                                   !5, $17
   13    17        TYPE_CHECK                                    2          !5
         18      > JMPZ                                                     ~19, ->20
   14    19    > > JMP                                                      ->53
   16    20    >   ASSIGN                                                   !6, 1
   17    21      > JMP                                                      ->24
   18    22    >   PRE_INC                                                  !6
   19    23        UNSET_DIM                                                !0, !7
   17    24    >   INIT_FCALL                                               'array_search'
         25        SEND_VAR                                                 !5
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $22     
         28        ASSIGN                                           ~23     !7, $22
         29        TYPE_CHECK                                  1018          ~23
         30      > JMPNZ                                                    ~24, ->22
   22    31    >   IS_EQUAL                                                 !6, 1
         32      > JMPZ                                                     ~25, ->38
   23    33    >   INIT_FCALL                                               'array_push'
         34        SEND_REF                                                 !3
         35        SEND_VAR                                                 !5
         36        DO_ICALL                                                 
         37      > JMP                                                      ->50
   25    38    >   ASSIGN                                                   !8, <array>
   26    39        ASSIGN                                                   !4, 0
         40      > JMP                                                      ->44
   27    41    >   ASSIGN_DIM                                               !8
         42        OP_DATA                                                  !5
   26    43        PRE_INC                                                  !4
         44    >   IS_SMALLER                                               !4, !6
         45      > JMPNZ                                                    ~31, ->41
   28    46    >   PRE_INC                                                  !2
   29    47        CONCAT                                           ~33     'dupe', !2
         48        ASSIGN_DIM                                               !3, ~33
         49        OP_DATA                                                  !8
   11    50    >   PRE_INC                                                  !4
         51    >   IS_SMALLER                                               !4, !1
         52      > JMPNZ                                                    ~36, ->13
   34    53    >   INIT_FCALL                                               'print_r'
         54        SEND_VAR                                                 !0
         55        DO_ICALL                                                 
   35    56        INIT_FCALL                                               'print_r'
         57        SEND_VAR                                                 !3
         58        DO_ICALL                                                 
         59      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.35 ms | 1400 KiB | 25 Q