3v4l.org

run code in 500+ 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 = 8, Position 2 = 27
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 27
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 26
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/i1WKI
function name:  (null)
number of ops:  40
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        FRAMELESS_ICALL_2                implode             ~10     '%2C', !0
          6        ASSIGN                                                       !2, ~10
    7     7      > FE_RESET_R                                           $12     !1, ->27
          8    > > FE_FETCH_R                                                   $12, !3, ->27
    9     9    >   INIT_FCALL                                                   'substr_count'
         10        SEND_VAR                                                     !2
         11        SEND_VAR                                                     !3
         12        DO_ICALL                                             $13     
         13        ASSIGN                                                       !4, $13
   12    14        IS_SMALLER                                                   1, !4
         15      > JMPZ                                                         ~15, ->26
   14    16    >   FRAMELESS_ICALL_2                strpos              ~16     !2, !3
         17        ASSIGN                                                       !5, ~16
   15    18        INIT_FCALL                                                   'substr_replace'
         19        SEND_VAR                                                     !2
         20        SEND_VAL                                                     ''
         21        SEND_VAR                                                     !5
         22        STRLEN                                               ~18     !3
         23        SEND_VAL                                                     ~18
         24        DO_ICALL                                             $19     
         25        ASSIGN                                                       !2, $19
    7    26    > > JMP                                                          ->8
         27    >   FE_FREE                                                      $12
   20    28        INIT_FCALL                                                   'array_filter'
         29        INIT_FCALL                                                   'explode'
         30        SEND_VAL                                                     '%2C'
         31        SEND_VAR                                                     !2
         32        DO_ICALL                                             $21     
         33        SEND_VAR                                                     $21
         34        DO_ICALL                                             $22     
         35        ASSIGN                                                       !6, $22
   22    36        INIT_FCALL                                                   'var_dump'
         37        SEND_VAR                                                     !6
         38        DO_ICALL                                                     
         39      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.66 ms | 1745 KiB | 19 Q