3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Remove duplicate elements from an array using a user-defined Reductor function. * @param array $array * @param callable $reductor Reduces a single array element to a simple type for equivalence checking. */ function array_uunique(array $array, callable $reductor) { $seen = []; return array_filter( $array, function($a)use(&$seen, $reductor){ $val = $reductor($a); if( ! in_array($val, $seen, true) ) { $seen[] = $val; return true; } else { return false; } } ); } $arr = [ [ 'target' => 'a' ], [ 'target' => 'b' ], [ 'target' => 'c' ], [ 'target' => 'd' ], [ 'target' => 'c' ], [ 'target' => 'e' ], ]; echo json_encode( array_uunique($arr, function($a){return $a['target'];}), JSON_PRETTY_PRINT ) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f31ft
function name:  (null)
number of ops:  13
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, <array>
   33     1        INIT_FCALL                                               'json_encode'
          2        INIT_FCALL                                               'array_uunique'
          3        SEND_VAR                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ff31ft%3A33%241'
          5        SEND_VAL                                                 ~2
          6        DO_FCALL                                      0  $3      
          7        SEND_VAR                                                 $3
          8        SEND_VAL                                                 128
          9        DO_ICALL                                         $4      
         10        CONCAT                                           ~5      $4, '%0A'
         11        ECHO                                                     ~5
         12      > RETURN                                                   1

Function array_uunique:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f31ft
function name:  array_uunique
number of ops:  12
compiled vars:  !0 = $array, !1 = $reductor, !2 = $seen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        ASSIGN                                                   !2, <array>
   10     3        INIT_FCALL                                               'array_filter'
   11     4        SEND_VAR                                                 !0
   12     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ff31ft%3A12%240'
          6        BIND_LEXICAL                                             ~4, !2
          7        BIND_LEXICAL                                             ~4, !1
   20     8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10      > RETURN                                                   $5
   22    11*     > RETURN                                                   null

End of function array_uunique

Function %00%7Bclosure%7D%2Fin%2Ff31ft%3A12%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f31ft
function name:  {closure}
number of ops:  20
compiled vars:  !0 = $a, !1 = $seen, !2 = $reductor, !3 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   13     3        INIT_DYNAMIC_CALL                                        !2
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !3, $4
   14     7        INIT_FCALL                                               'in_array'
          8        SEND_VAR                                                 !3
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $6      
         12        BOOL_NOT                                         ~7      $6
         13      > JMPZ                                                     ~7, ->18
   15    14    >   ASSIGN_DIM                                               !1
         15        OP_DATA                                                  !3
   16    16      > RETURN                                                   <true>
         17*       JMP                                                      ->19
   18    18    > > RETURN                                                   <false>
   20    19*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ff31ft%3A12%240

Function %00%7Bclosure%7D%2Fin%2Ff31ft%3A33%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f31ft
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'target'
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ff31ft%3A33%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.4 ms | 1403 KiB | 20 Q