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[$lookup][] = array_merge((array) $results[$lookup], (array) $output[$lookup]); } else { $output[$lookup] = array_merge($results, $output); } } } 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/2eCq6
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 = 8
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 38
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 32
Branch analysis from position: 20
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: 32
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
Branch analysis from position: 38
Branch analysis from position: 8
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/2eCq6
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, ->8
   11     8    >   TYPE_CHECK                                  128          !3
          9      > JMPZ                                                     ~11, ->38
   12    10    >   INIT_FCALL_BY_NAME                                       'coolPluck'
         11        SEND_VAR_EX                                              !3
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0  $12     
         14        ASSIGN                                                   !5, $12
   13    15        ISSET_ISEMPTY_DIM_OBJ                         0  ~14     !5, !1
         16      > JMPZ_EX                                          ~14     ~14, ->19
         17    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~15     !2, !1
         18        BOOL                                             ~14     ~15
         19    > > JMPZ                                                     ~14, ->32
   15    20    >   INIT_FCALL                                               'array_merge'
         21        FETCH_DIM_R                                      ~18     !5, !1
         22        CAST                                          7  ~19     ~18
         23        SEND_VAL                                                 ~19
         24        FETCH_DIM_R                                      ~20     !2, !1
         25        CAST                                          7  ~21     ~20
         26        SEND_VAL                                                 ~21
         27        DO_ICALL                                         $22     
         28        FETCH_DIM_W                                      $16     !2, !1
         29        ASSIGN_DIM                                               $16
         30        OP_DATA                                                  $22
         31      > JMP                                                      ->38
   19    32    >   INIT_FCALL                                               'array_merge'
         33        SEND_VAR                                                 !5
         34        SEND_VAR                                                 !2
         35        DO_ICALL                                         $24     
         36        ASSIGN_DIM                                               !2, !1
         37        OP_DATA                                                  $24
    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:
164.64 ms | 1407 KiB | 18 Q