3v4l.org

run code in 300+ PHP versions simultaneously
<?php function coolPluck($array, $lookup) { $output = array(); foreach($array as $k => $v) { if($k === $lookup) { $output[$k] = $v; } if(is_array($v)) { $results = coolPluck($v, $lookup); if(isset($results[$lookup]) && isset($output[$lookup])) { $output[] = array_merge((array) $output[$lookup], (array) $results[$lookup]); } else { $output = array_merge($output, $results); } } } return $output; } $testArray = array('test' => array('percy' => array('percy' => 'hatcherson'), 'percy' => array('mitchell', 'anderson'))); var_dump(coolPluck($testArray, 'percy'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JGpo0
function name:  (null)
number of ops:  9
compiled vars:  !0 = $testArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, <array>
   31     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'coolpluck'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'percy'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function coolpluck:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 39
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 39
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 38
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 33
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 21
Branch analysis from position: 38
Branch analysis from position: 10
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/JGpo0
function name:  coolPluck
number of ops:  42
compiled vars:  !0 = $array, !1 = $lookup, !2 = $output, !3 = $v, !4 = $k, !5 = $results
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ASSIGN                                                   !2, <array>
    7     3      > FE_RESET_R                                       $7      !0, ->39
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->39
          5    >   ASSIGN                                                   !4, ~8
    8     6        IS_IDENTICAL                                             !4, !1
          7      > JMPZ                                                     ~10, ->10
    9     8    >   ASSIGN_DIM                                               !2, !4
          9        OP_DATA                                                  !3
   11    10    >   TYPE_CHECK                                  128          !3
         11      > JMPZ                                                     ~12, ->38
   12    12    >   INIT_FCALL_BY_NAME                                       'coolPluck'
         13        SEND_VAR_EX                                              !3
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0  $13     
         16        ASSIGN                                                   !5, $13
   13    17        ISSET_ISEMPTY_DIM_OBJ                         0  ~15     !5, !1
         18      > JMPZ_EX                                          ~15     ~15, ->21
         19    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~16     !2, !1
         20        BOOL                                             ~15     ~16
         21    > > JMPZ                                                     ~15, ->33
   15    22    >   INIT_FCALL                                               'array_merge'
         23        FETCH_DIM_R                                      ~18     !2, !1
         24        CAST                                          7  ~19     ~18
         25        SEND_VAL                                                 ~19
         26        FETCH_DIM_R                                      ~20     !5, !1
         27        CAST                                          7  ~21     ~20
         28        SEND_VAL                                                 ~21
         29        DO_ICALL                                         $22     
         30        ASSIGN_DIM                                               !2
         31        OP_DATA                                                  $22
         32      > JMP                                                      ->38
   19    33    >   INIT_FCALL                                               'array_merge'
         34        SEND_VAR                                                 !2
         35        SEND_VAR                                                 !5
         36        DO_ICALL                                         $23     
         37        ASSIGN                                                   !2, $23
    7    38    > > JMP                                                      ->4
         39    >   FE_FREE                                                  $7
   24    40      > RETURN                                                   !2
   25    41*     > RETURN                                                   null

End of function coolpluck

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.42 ms | 1394 KiB | 18 Q