3v4l.org

run code in 300+ 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 **/ // Build temporary array for array_unique $tmp = array(); foreach($array as $k => $v) $tmp[$k] = $v->name; // Find duplicates in temporary array $tmp = array_unique($tmp); // Build new array with only non-duplicate items $filtered = []; foreach($array as $k => $v) { if (array_key_exists($k, $tmp)) $filtered[$k] = $v; } /** Answer Code ends here **/ echo 'After removing duplicates\n'; print_r($filtered);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 34
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 48
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 48
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 47
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
Branch analysis from position: 34
filename:       /in/SCrko
function name:  (null)
number of ops:  54
compiled vars:  !0 = $objA, !1 = $objB, !2 = $objC, !3 = $array, !4 = $tmp, !5 = $v, !6 = $k, !7 = $filtered
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $8      'my_obj'
          1        SEND_VAL_EX                                              23
          2        SEND_VAL_EX                                              'Assasination'
          3        SEND_VAL_EX                                              'assasination'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $8
   18     6        NEW                                              $11     '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, $11
   19    12        NEW                                              $14     '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, $14
   21    18        INIT_ARRAY                                       ~17     !0
         19        ADD_ARRAY_ELEMENT                                ~17     !1
         20        ADD_ARRAY_ELEMENT                                ~17     !2
         21        ASSIGN                                                   !3, ~17
   23    22        ECHO                                                     'Original+array%3A%5Cn'
   24    23        INIT_FCALL                                               'print_r'
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                                 
   29    26        ASSIGN                                                   !4, <array>
   30    27      > FE_RESET_R                                       $21     !3, ->34
         28    > > FE_FETCH_R                                       ~22     $21, !5, ->34
         29    >   ASSIGN                                                   !6, ~22
   31    30        FETCH_OBJ_R                                      ~25     !5, 'name'
         31        ASSIGN_DIM                                               !4, !6
         32        OP_DATA                                                  ~25
   30    33      > JMP                                                      ->28
         34    >   FE_FREE                                                  $21
   34    35        INIT_FCALL                                               'array_unique'
         36        SEND_VAR                                                 !4
         37        DO_ICALL                                         $26     
         38        ASSIGN                                                   !4, $26
   37    39        ASSIGN                                                   !7, <array>
   38    40      > FE_RESET_R                                       $29     !3, ->48
         41    > > FE_FETCH_R                                       ~30     $29, !5, ->48
         42    >   ASSIGN                                                   !6, ~30
   40    43        ARRAY_KEY_EXISTS                                         !6, !4
         44      > JMPZ                                                     ~32, ->47
   41    45    >   ASSIGN_DIM                                               !7, !6
         46        OP_DATA                                                  !5
   38    47    > > JMP                                                      ->41
         48    >   FE_FREE                                                  $29
   46    49        ECHO                                                     'After+removing+duplicates%5Cn'
   47    50        INIT_FCALL                                               'print_r'
         51        SEND_VAR                                                 !7
         52        DO_ICALL                                                 
         53      > 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/SCrko
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.0.0


preferences:
137.09 ms | 1004 KiB | 15 Q