3v4l.org

run code in 300+ PHP versions simultaneously
<?php function unique_multidim_array($array, $key) { $uniq = []; foreach($array as $val) { $curVal = $val[$key]; // shortcut of the value $uniq[$curVal] = $val; // override previous value if exists } return array_values($uniq); // array_values to re-index array } $exists = [ ['intervention_id' => 2, 'exists' => 'yes'], ['intervention_id' => 2, 'exists' => 'no'], ['intervention_id' => 2, 'exists' => 'yes'], ['intervention_id' => 5, 'exists' => 'yes'], ['intervention_id' => 6, 'exists' => 'no'], ['intervention_id' => 12, 'exists' => 'yes'], ]; $uniq = unique_multidim_array($exists, 'intervention_id'); print_r($uniq);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A8JaL
function name:  (null)
number of ops:  10
compiled vars:  !0 = $exists, !1 = $uniq
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   20     1        INIT_FCALL                                               'unique_multidim_array'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'intervention_id'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   21     6        INIT_FCALL                                               'print_r'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function unique_multidim_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/A8JaL
function name:  unique_multidim_array
number of ops:  16
compiled vars:  !0 = $array, !1 = $key, !2 = $uniq, !3 = $val, !4 = $curVal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3      > FE_RESET_R                                       $6      !0, ->10
          4    > > FE_FETCH_R                                               $6, !3, ->10
    6     5    >   FETCH_DIM_R                                      ~7      !3, !1
          6        ASSIGN                                                   !4, ~7
    7     7        ASSIGN_DIM                                               !2, !4
          8        OP_DATA                                                  !3
    5     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $6
    9    11        INIT_FCALL                                               'array_values'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $10     
         14      > RETURN                                                   $10
   10    15*     > RETURN                                                   null

End of function unique_multidim_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.46 ms | 944 KiB | 19 Q