3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ('1' => (object)array( 'id' => 225, 'user_id' => 1, 'name' => 'Blue Quilted Leather Jacket by Minusey - $499' ), '2' => (object)array( 'id' => 222, 'user_id' => 1, 'name' => 'Darling New Bathtub by Duravit - $6300' ), '3' => (object)array( 'id' => 222, 'user_id' => 1, 'name' => 'Darling New Bathtub by Duravit - $6300' ) ); //print_r(array_column((array)$array, 'id')); function array_unique_by_key($array, $key = 'id') { $found = array(); // Encountered IDs $out = array(); // Output array foreach ($array as $value) { if (!array_key_exists($key, $value)) throw new Exception('Can\'t find key "' . $key . '"'); $id = $value[$key]; // If already encountered, skip if (in_array($id, $found)) continue; // Otherwise, add to found values and to output array $found[] = $id; $out[] = $value; } return $out; } print_r(array_unique_by_key($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JI5OK
function name:  (null)
number of ops:  14
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   CAST                                          8  ~1      <array>
          1        INIT_ARRAY                                       ~2      ~1, 1
   10     2        CAST                                          8  ~3      <array>
          3        ADD_ARRAY_ELEMENT                                ~2      ~3, 2
   16     4        CAST                                          8  ~4      <array>
          5        ADD_ARRAY_ELEMENT                                ~2      ~4, 3
    3     6        ASSIGN                                                   !0, ~2
   41     7        INIT_FCALL                                               'print_r'
          8        INIT_FCALL                                               'array_unique_by_key'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function array_unique_by_key:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 28
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 28
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/JI5OK
function name:  array_unique_by_key
number of ops:  31
compiled vars:  !0 = $array, !1 = $key, !2 = $found, !3 = $out, !4 = $value, !5 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'id'
   24     2        ASSIGN                                                   !2, <array>
   25     3        ASSIGN                                                   !3, <array>
   27     4      > FE_RESET_R                                       $8      !0, ->28
          5    > > FE_FETCH_R                                               $8, !4, ->28
   28     6    >   ARRAY_KEY_EXISTS                                 ~9      !1, !4
          7        BOOL_NOT                                         ~10     ~9
          8      > JMPZ                                                     ~10, ->15
          9    >   NEW                                              $11     'Exception'
         10        CONCAT                                           ~12     'Can%27t+find+key+%22', !1
         11        CONCAT                                           ~13     ~12, '%22'
         12        SEND_VAL_EX                                              ~13
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $11
   29    15    >   FETCH_DIM_R                                      ~15     !4, !1
         16        ASSIGN                                                   !5, ~15
   32    17        INIT_FCALL                                               'in_array'
         18        SEND_VAR                                                 !5
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $17     
         21      > JMPZ                                                     $17, ->23
         22    > > JMP                                                      ->5
   35    23    >   ASSIGN_DIM                                               !2
         24        OP_DATA                                                  !5
   36    25        ASSIGN_DIM                                               !3
         26        OP_DATA                                                  !4
   27    27      > JMP                                                      ->5
         28    >   FE_FREE                                                  $8
   39    29      > RETURN                                                   !3
   40    30*     > RETURN                                                   null

End of function array_unique_by_key

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.29 ms | 1407 KiB | 18 Q