3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ "one" => ["id" => 111, "name" => "Jhon"], "two" => ["id" => 222, "name" => "Adam"], "three" => ["id" => 111, "name" => "Mark"], "four" => ["id" => 125, "name" => "Jhon"], "five" => ["id" => 111, "name" => "Jhon"], "six" => ["id" => 222, "name" => "Rock"], ]; // store added IDs $added = []; // filter array (need to pass $added as reference to be updated) $output = array_filter($array, function($item) use (&$added) { // shortcut for readability $id = $item['id']; // Check if id already exists if (isset($added[$id])) { return false; } // add to reference $added[$id] = true; // add to final array return true; }); unset($added); // no longer needed. var_dump($output);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ide7a
function name:  (null)
number of ops:  14
compiled vars:  !0 = $array, !1 = $added, !2 = $output
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   12     1        ASSIGN                                                       !1, <array>
   15     2        INIT_FCALL                                                   'array_filter'
          3        SEND_VAR                                                     !0
          4        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
          5        BIND_LEXICAL                                                 ~5, !1
   25     6        SEND_VAL                                                     ~5
   15     7        DO_ICALL                                             $6      
          8        ASSIGN                                                       !2, $6
   27     9        UNSET_CV                                                     !1
   29    10        INIT_FCALL                                                   'var_dump'
         11        SEND_VAR                                                     !2
         12        DO_ICALL                                                     
         13      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ide7a
function name:  {closure:/in/ide7a:15}
number of ops:  11
compiled vars:  !0 = $item, !1 = $added, !2 = $id
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   18     2        FETCH_DIM_R                                          ~3      !0, 'id'
          3        ASSIGN                                                       !2, ~3
   20     4        ISSET_ISEMPTY_DIM_OBJ                             0          !1, !2
          5      > JMPZ                                                         ~5, ->7
          6    > > RETURN                                                       <false>
   22     7    >   ASSIGN_DIM                                                   !1, !2
          8        OP_DATA                                                      <true>
   24     9      > RETURN                                                       <true>
   25    10*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.03 ms | 2041 KiB | 15 Q