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])) { if (is_array($output)) { $output[$lookup] = array_merge($output[$lookup], $results[$lookup]); } else { $output[$lookup] = array($output[$lookup], $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/tfrn7
function name:  (null)
number of ops:  9
compiled vars:  !0 = $testArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ASSIGN                                                   !0, <array>
   35     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 = 46
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 46
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 = 45
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 = 40
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 33
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
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 = 45
Branch analysis from position: 45
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 21
Branch analysis from position: 45
Branch analysis from position: 10
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
filename:       /in/tfrn7
function name:  coolPluck
number of ops:  49
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, ->46
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->46
          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, ->45
   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, ->40
   15    22    >   TYPE_CHECK                                  128          !2
         23      > JMPZ                                                     ~17, ->33
   16    24    >   INIT_FCALL                                               'array_merge'
         25        FETCH_DIM_R                                      ~19     !2, !1
         26        SEND_VAL                                                 ~19
         27        FETCH_DIM_R                                      ~20     !5, !1
         28        SEND_VAL                                                 ~20
         29        DO_ICALL                                         $21     
         30        ASSIGN_DIM                                               !2, !1
         31        OP_DATA                                                  $21
         32      > JMP                                                      ->39
   18    33    >   FETCH_DIM_R                                      ~23     !2, !1
         34        INIT_ARRAY                                       ~24     ~23
         35        FETCH_DIM_R                                      ~25     !5, !1
         36        ADD_ARRAY_ELEMENT                                ~24     ~25
         37        ASSIGN_DIM                                               !2, !1
         38        OP_DATA                                                  ~24
         39    > > JMP                                                      ->45
   23    40    >   INIT_FCALL                                               'array_merge'
         41        SEND_VAR                                                 !2
         42        SEND_VAR                                                 !5
         43        DO_ICALL                                         $26     
         44        ASSIGN                                                   !2, $26
    7    45    > > JMP                                                      ->4
         46    >   FE_FREE                                                  $7
   28    47      > RETURN                                                   !2
   29    48*     > RETURN                                                   null

End of function coolpluck

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.91 ms | 1402 KiB | 18 Q