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+1] = $v; } if(is_array($v)) { $results = coolPluck($v, $lookup); if(isset($results[$lookup]) && isset($output[$lookup])) { $output = array_merge((array) $results[$lookup], (array) $output[$lookup]); } else { $output = array_merge($results, $output); } } } return $output; } $testArray = array('test' => array('percy' => array('percy' => 'hatcherson'), 'percy' => array('mitchell', 'anderson'))); var_dump(coolPluck($testArray, 'test'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/js3Gu
function name:  (null)
number of ops:  9
compiled vars:  !0 = $testArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ASSIGN                                                   !0, <array>
   33     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'coolpluck'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'test'
          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 = 11
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 38
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
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: 22
Branch analysis from position: 38
Branch analysis from position: 11
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/js3Gu
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, ->11
    9     8    >   ADD                                              ~11     !4, 1
          9        ASSIGN_DIM                                               !2, ~11
         10        OP_DATA                                                  !3
   11    11    >   TYPE_CHECK                                  128          !3
         12      > JMPZ                                                     ~13, ->38
   12    13    >   INIT_FCALL_BY_NAME                                       'coolPluck'
         14        SEND_VAR_EX                                              !3
         15        SEND_VAR_EX                                              !1
         16        DO_FCALL                                      0  $14     
         17        ASSIGN                                                   !5, $14
   13    18        ISSET_ISEMPTY_DIM_OBJ                         0  ~16     !5, !1
         19      > JMPZ_EX                                          ~16     ~16, ->22
         20    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~17     !2, !1
         21        BOOL                                             ~16     ~17
         22    > > JMPZ                                                     ~16, ->33
   15    23    >   INIT_FCALL                                               'array_merge'
         24        FETCH_DIM_R                                      ~18     !5, !1
         25        CAST                                          7  ~19     ~18
         26        SEND_VAL                                                 ~19
         27        FETCH_DIM_R                                      ~20     !2, !1
         28        CAST                                          7  ~21     ~20
         29        SEND_VAL                                                 ~21
         30        DO_ICALL                                         $22     
         31        ASSIGN                                                   !2, $22
         32      > JMP                                                      ->38
   20    33    >   INIT_FCALL                                               'array_merge'
         34        SEND_VAR                                                 !5
         35        SEND_VAR                                                 !2
         36        DO_ICALL                                         $24     
         37        ASSIGN                                                   !2, $24
    7    38    > > JMP                                                      ->4
         39    >   FE_FREE                                                  $7
   26    40      > RETURN                                                   !2
   27    41*     > RETURN                                                   null

End of function coolpluck

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.98 ms | 1394 KiB | 18 Q