3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_words = ['harmony', 'Acrobat', 'harmony', 'harmony']; $array_words_unique = array_unique($array_words); //get a list of unique words from the original array $array_str = implode(",", $array_words); foreach ($array_words_unique as $word) { //count how many times the word occurs $count = substr_count($array_str, $word); //if it occurs more than once, remove the first occurence if ($count > 1) { //find the first position of the word in the string, then replace that with nothing $pos = strpos($array_str, $word); $array_str = substr_replace($array_str, "", $pos, strlen($word)); } } //convert back to an array, and filter any blank entries caused by commas with nothing between them $array_final = array_filter(explode(",", $array_str)); var_dump($array_final);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 33
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 33
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 32
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 32
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/i1WKI
function name:  (null)
number of ops:  46
compiled vars:  !0 = $array_words, !1 = $array_words_unique, !2 = $array_str, !3 = $word, !4 = $count, !5 = $pos, !6 = $array_final
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'array_unique'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $8      
          4        ASSIGN                                                   !1, $8
    5     5        INIT_FCALL                                               'implode'
          6        SEND_VAL                                                 '%2C'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !2, $10
    7    10      > FE_RESET_R                                       $12     !1, ->33
         11    > > FE_FETCH_R                                               $12, !3, ->33
    9    12    >   INIT_FCALL                                               'substr_count'
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                         $13     
         16        ASSIGN                                                   !4, $13
   12    17        IS_SMALLER                                               1, !4
         18      > JMPZ                                                     ~15, ->32
   14    19    >   INIT_FCALL                                               'strpos'
         20        SEND_VAR                                                 !2
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                         $16     
         23        ASSIGN                                                   !5, $16
   15    24        INIT_FCALL                                               'substr_replace'
         25        SEND_VAR                                                 !2
         26        SEND_VAL                                                 ''
         27        SEND_VAR                                                 !5
         28        STRLEN                                           ~18     !3
         29        SEND_VAL                                                 ~18
         30        DO_ICALL                                         $19     
         31        ASSIGN                                                   !2, $19
    7    32    > > JMP                                                      ->11
         33    >   FE_FREE                                                  $12
   20    34        INIT_FCALL                                               'array_filter'
         35        INIT_FCALL                                               'explode'
         36        SEND_VAL                                                 '%2C'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                         $21     
         39        SEND_VAR                                                 $21
         40        DO_ICALL                                         $22     
         41        ASSIGN                                                   !6, $22
   22    42        INIT_FCALL                                               'var_dump'
         43        SEND_VAR                                                 !6
         44        DO_ICALL                                                 
         45      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.45 ms | 1018 KiB | 21 Q