3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( array( "name" => "a", "code" => "416", "id" => "a1" ), array( "name" => "a", "code" => "522", "id" => "a2" ), array( "name" => "b", "code" => "580", "id" => "b1" ) ); $counts = array_count_values( array_map(function (array $entry) { return $entry['name']; }, $array) // or array_column($array, 'name') in PHP 5.5+ ); $uniqueNames = array_keys( array_filter($counts, function ($count) { return $count == 1; }) ); $result = array_filter($array, function (array $entry) use ($uniqueNames) { return in_array($entry['name'], $uniqueNames); }); $codes = array ("code"); //var_dump(array_intersect_key($result,array_flip($codes))); var_dump($codes);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TGPAf
function name:  (null)
number of ops:  31
compiled vars:  !0 = $array, !1 = $counts, !2 = $uniqueNames, !3 = $result, !4 = $codes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   21     1        INIT_FCALL                                               'array_count_values'
   22     2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTGPAf%3A22%240'
          4        SEND_VAL                                                 ~6
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $7      
          7        SEND_VAR                                                 $7
          8        DO_ICALL                                         $8      
   21     9        ASSIGN                                                   !1, $8
   26    10        INIT_FCALL                                               'array_keys'
   27    11        INIT_FCALL                                               'array_filter'
         12        SEND_VAR                                                 !1
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTGPAf%3A27%241'
         14        SEND_VAL                                                 ~10
         15        DO_ICALL                                         $11     
         16        SEND_VAR                                                 $11
         17        DO_ICALL                                         $12     
   26    18        ASSIGN                                                   !2, $12
   30    19        INIT_FCALL                                               'array_filter'
         20        SEND_VAR                                                 !0
         21        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTGPAf%3A30%242'
         22        BIND_LEXICAL                                             ~14, !2
   32    23        SEND_VAL                                                 ~14
         24        DO_ICALL                                         $15     
   30    25        ASSIGN                                                   !3, $15
   35    26        ASSIGN                                                   !4, <array>
   37    27        INIT_FCALL                                               'var_dump'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FTGPAf%3A22%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TGPAf
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'name'
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTGPAf%3A22%240

Function %00%7Bclosure%7D%2Fin%2FTGPAf%3A27%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TGPAf
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        IS_EQUAL                                         ~1      !0, 1
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTGPAf%3A27%241

Function %00%7Bclosure%7D%2Fin%2FTGPAf%3A30%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TGPAf
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $entry, !1 = $uniqueNames
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   31     2        INIT_FCALL                                               'in_array'
          3        FETCH_DIM_R                                      ~2      !0, 'name'
          4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7      > RETURN                                                   $3
   32     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTGPAf%3A30%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.56 ms | 1400 KiB | 25 Q