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

End of function coolpluck

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.98 ms | 1403 KiB | 18 Q