3v4l.org

run code in 300+ PHP versions simultaneously
<?php $actualArray = array( user1 => array( 'name' => 'User1', 'age' => '25', 'lastLogin' => '2013-08-16' ), user1 => array( 'name' => 'User1', 'age' => '25', 'lastLogin' => '2013-08-10' ), user2 => array( 'name' => 'User2', 'age' => '35', 'lastLogin' => '2013-08-08' ), user1 => array( 'name' => 'User1', 'age' => '25', 'lastLogin' => '2013-07-10' ) ); function uniqueAssocArray($array, $uniqueKey) { if (!is_array($array)) { return array(); } $uniqueKeys = array(); foreach ($array as $key => $item) { if (!in_array($item[$uniqueKey], $uniqueKeys)) { $uniqueKeys[$item[$uniqueKey]] = $item; } } return $uniqueKeys; } print_r(uniqueAssocArray($actualArray, 'name'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/I7U2u
function name:  (null)
number of ops:  17
compiled vars:  !0 = $actualArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   FETCH_CONSTANT                                   ~1      'user1'
    4     1        INIT_ARRAY                                       ~2      <array>, ~1
    8     2        FETCH_CONSTANT                                   ~3      'user1'
    4     3        ADD_ARRAY_ELEMENT                                ~2      <array>, ~3
   13     4        FETCH_CONSTANT                                   ~4      'user2'
    4     5        ADD_ARRAY_ELEMENT                                ~2      <array>, ~4
   18     6        FETCH_CONSTANT                                   ~5      'user1'
    4     7        ADD_ARRAY_ELEMENT                                ~2      <array>, ~5
    2     8        ASSIGN                                                   !0, ~2
   36     9        INIT_FCALL                                               'print_r'
         10        INIT_FCALL                                               'uniqueassocarray'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 'name'
         13        DO_FCALL                                      0  $7      
         14        SEND_VAR                                                 $7
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function uniqueassocarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 20
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/I7U2u
function name:  uniqueAssocArray
number of ops:  24
compiled vars:  !0 = $array, !1 = $uniqueKey, !2 = $uniqueKeys, !3 = $item, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        TYPE_CHECK                                  128  ~5      !0
          3        BOOL_NOT                                         ~6      ~5
          4      > JMPZ                                                     ~6, ->6
   26     5    > > RETURN                                                   <array>
   28     6    >   ASSIGN                                                   !2, <array>
   29     7      > FE_RESET_R                                       $8      !0, ->21
          8    > > FE_FETCH_R                                       ~9      $8, !3, ->21
          9    >   ASSIGN                                                   !4, ~9
   30    10        INIT_FCALL                                               'in_array'
         11        FETCH_DIM_R                                      ~11     !3, !1
         12        SEND_VAL                                                 ~11
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $12     
         15        BOOL_NOT                                         ~13     $12
         16      > JMPZ                                                     ~13, ->20
   31    17    >   FETCH_DIM_R                                      ~14     !3, !1
         18        ASSIGN_DIM                                               !2, ~14
         19        OP_DATA                                                  !3
   29    20    > > JMP                                                      ->8
         21    >   FE_FREE                                                  $8
   34    22      > RETURN                                                   !2
   35    23*     > RETURN                                                   null

End of function uniqueassocarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.91 ms | 1403 KiB | 18 Q