3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = ["a", "b", "a", "c"]; function makeUnique($arr){ $set = []; foreach($arr as $k => $v){ $set[ $v ] = ($set[ $v ] ?? 0) + 1; $arr[ $k ] = $arr[ $k ] . ($set[ $v ] > 1 ? '.' .($set[ $v ] - 1) : ''); } return $arr; } print_r(makeUnique($arr));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Rh6RJ
function name:  (null)
number of ops:  8
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'makeunique'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function makeunique:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/Rh6RJ
function name:  makeUnique
number of ops:  28
compiled vars:  !0 = $arr, !1 = $set, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        ASSIGN                                                   !1, <array>
    7     2      > FE_RESET_R                                       $5      !0, ->25
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->25
          4    >   ASSIGN                                                   !3, ~6
    8     5        FETCH_DIM_IS                                     ~9      !1, !2
          6        COALESCE                                         ~10     ~9
          7        QM_ASSIGN                                        ~10     0
          8        ADD                                              ~11     ~10, 1
          9        ASSIGN_DIM                                               !1, !2
         10        OP_DATA                                                  ~11
    9    11        FETCH_DIM_R                                      ~13     !0, !3
         12        FETCH_DIM_R                                      ~14     !1, !2
         13        IS_SMALLER                                               1, ~14
         14      > JMPZ                                                     ~15, ->20
         15    >   FETCH_DIM_R                                      ~16     !1, !2
         16        SUB                                              ~17     ~16, 1
         17        CONCAT                                           ~18     '.', ~17
         18        QM_ASSIGN                                        ~19     ~18
         19      > JMP                                                      ->21
         20    >   QM_ASSIGN                                        ~19     ''
         21    >   CONCAT                                           ~20     ~13, ~19
         22        ASSIGN_DIM                                               !0, !3
         23        OP_DATA                                                  ~20
    7    24      > JMP                                                      ->3
         25    >   FE_FREE                                                  $5
   11    26      > RETURN                                                   !0
   12    27*     > RETURN                                                   null

End of function makeunique

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.62 ms | 1017 KiB | 15 Q