3v4l.org

run code in 500+ PHP versions simultaneously
<?php class my_obj { public $term_id; public $name; public $slug; public function __construct($i, $n, $s) { $this->term_id = $i; $this->name = $n; $this->slug = $s; } } $objA = new my_obj(23, "Assasination", "assasination"); $objB = new my_obj(14, "Campaign Finance", "campaign-finance"); $objC = new my_obj(15, "Campaign Finance", "campaign-finance-good-government-political-reform"); $array = array($objA, $objB, $objC); echo "Original array:\n"; print_r($array); /** Answer Code begins here */ $filtered = array_intersect_key($array, array_unique(array_column($array, 'name'))); /** Answer Code ends here */ echo "After removing duplicates\n"; print_r($filtered);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IboLu
function name:  (null)
number of ops:  43
compiled vars:  !0 = $objA, !1 = $objB, !2 = $objC, !3 = $array, !4 = $filtered
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   NEW                                                  $5      'my_obj'
          1        SEND_VAL_EX                                                  23
          2        SEND_VAL_EX                                                  'Assasination'
          3        SEND_VAL_EX                                                  'assasination'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !0, $5
   18     6        NEW                                                  $8      'my_obj'
          7        SEND_VAL_EX                                                  14
          8        SEND_VAL_EX                                                  'Campaign+Finance'
          9        SEND_VAL_EX                                                  'campaign-finance'
         10        DO_FCALL                                          0          
         11        ASSIGN                                                       !1, $8
   19    12        NEW                                                  $11     'my_obj'
         13        SEND_VAL_EX                                                  15
         14        SEND_VAL_EX                                                  'Campaign+Finance'
         15        SEND_VAL_EX                                                  'campaign-finance-good-government-political-reform'
         16        DO_FCALL                                          0          
         17        ASSIGN                                                       !2, $11
   21    18        INIT_ARRAY                                           ~14     !0
         19        ADD_ARRAY_ELEMENT                                    ~14     !1
         20        ADD_ARRAY_ELEMENT                                    ~14     !2
         21        ASSIGN                                                       !3, ~14
   22    22        ECHO                                                         'Original+array%3A%0A'
   23    23        INIT_FCALL                                                   'print_r'
         24        SEND_VAR                                                     !3
         25        DO_ICALL                                                     
   26    26        INIT_FCALL                                                   'array_intersect_key'
         27        SEND_VAR                                                     !3
         28        INIT_FCALL                                                   'array_unique'
         29        INIT_FCALL                                                   'array_column'
         30        SEND_VAR                                                     !3
         31        SEND_VAL                                                     'name'
         32        DO_ICALL                                             $17     
         33        SEND_VAR                                                     $17
         34        DO_ICALL                                             $18     
         35        SEND_VAR                                                     $18
         36        DO_ICALL                                             $19     
         37        ASSIGN                                                       !4, $19
   29    38        ECHO                                                         'After+removing+duplicates%0A'
   30    39        INIT_FCALL                                                   'print_r'
         40        SEND_VAR                                                     !4
         41        DO_ICALL                                                     
         42      > RETURN                                                       1

Class my_obj:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IboLu
function name:  __construct
number of ops:  10
compiled vars:  !0 = $i, !1 = $n, !2 = $s
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   11     3        ASSIGN_OBJ                                                   'term_id'
          4        OP_DATA                                                      !0
   12     5        ASSIGN_OBJ                                                   'name'
          6        OP_DATA                                                      !1
   13     7        ASSIGN_OBJ                                                   'slug'
          8        OP_DATA                                                      !2
   14     9      > RETURN                                                       null

End of function __construct

End of class my_obj.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.21 ms | 1583 KiB | 17 Q