3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( 'foo' => 2, 'baz' => 3, 'bar' => 4, 'jim' => 2, ); function unique($input) { $output = array(); foreach ($input as $key => $val) { if (!in_array($val, $output)) { $output[$key] = $val; } } return $output; } function unique_better($input) { $output = array(); $unique_values = array(); foreach ($input as $key => $val) { if ( ! isset( $unique_values[$val] ) ) { $unique_values[$val] = true; $output[$key] = $val; } } return $output; } var_dump(unique($array)); var_dump(unique_better($array)); var_dump(array_flip(array_flip($array)));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oHVSb
function name:  (null)
number of ops:  23
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   33     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'unique'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
   34     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'unique_better'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $4      
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                                 
   35    13        INIT_FCALL                                               'var_dump'
         14        INIT_FCALL                                               'array_flip'
         15        INIT_FCALL                                               'array_flip'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $6      
         18        SEND_VAR                                                 $6
         19        DO_ICALL                                         $7      
         20        SEND_VAR                                                 $7
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Function unique:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/oHVSb
function name:  unique
number of ops:  17
compiled vars:  !0 = $input, !1 = $output, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        ASSIGN                                                   !1, <array>
   13     2      > FE_RESET_R                                       $5      !0, ->14
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->14
          4    >   ASSIGN                                                   !3, ~6
   14     5        INIT_FCALL                                               'in_array'
          6        SEND_VAR                                                 !2
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $8      
          9        BOOL_NOT                                         ~9      $8
         10      > JMPZ                                                     ~9, ->13
   15    11    >   ASSIGN_DIM                                               !1, !3
         12        OP_DATA                                                  !2
   13    13    > > JMP                                                      ->3
         14    >   FE_FREE                                                  $5
   19    15      > RETURN                                                   !1
   20    16*     > RETURN                                                   null

End of function unique

Function unique_better:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/oHVSb
function name:  unique_better
number of ops:  17
compiled vars:  !0 = $input, !1 = $output, !2 = $unique_values, !3 = $val, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        ASSIGN                                                   !1, <array>
   23     2        ASSIGN                                                   !2, <array>
   24     3      > FE_RESET_R                                       $7      !0, ->14
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->14
          5    >   ASSIGN                                                   !4, ~8
   25     6        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !2, !3
          7        BOOL_NOT                                         ~11     ~10
          8      > JMPZ                                                     ~11, ->13
   26     9    >   ASSIGN_DIM                                               !2, !3
         10        OP_DATA                                                  <true>
   27    11        ASSIGN_DIM                                               !1, !4
         12        OP_DATA                                                  !3
   24    13    > > JMP                                                      ->4
         14    >   FE_FREE                                                  $7
   30    15      > RETURN                                                   !1
   31    16*     > RETURN                                                   null

End of function unique_better

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.73 ms | 1403 KiB | 21 Q