3v4l.org

run code in 300+ PHP versions simultaneously
<?php function coolPluck($array, $lookup) { $output = array(); if(isset($array[$lookup])) $output[$lookup] = $array[$lookup]; 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('percy', 'hatcherson'), 'thomas' => 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/WrO6o
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                                                 '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 = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 41
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 41
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 40
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 35
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 27
Branch analysis from position: 40
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 8
filename:       /in/WrO6o
function name:  coolPluck
number of ops:  44
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        ISSET_ISEMPTY_DIM_OBJ                         0          !0, !1
          4      > JMPZ                                                     ~7, ->8
          5    >   FETCH_DIM_R                                      ~9      !0, !1
          6        ASSIGN_DIM                                               !2, !1
          7        OP_DATA                                                  ~9
    9     8    > > FE_RESET_R                                       $10     !0, ->41
          9    > > FE_FETCH_R                                       ~11     $10, !3, ->41
         10    >   ASSIGN                                                   !4, ~11
   10    11        IS_IDENTICAL                                             !4, !1
         12      > JMPZ                                                     ~13, ->16
   11    13    >   ASSIGN_DIM                                               !2, !4
         14        OP_DATA                                                  !3
         15      > JMP                                                      ->40
   13    16    >   TYPE_CHECK                                  128          !3
         17      > JMPZ                                                     ~15, ->40
   14    18    >   INIT_FCALL_BY_NAME                                       'coolPluck'
         19        SEND_VAR_EX                                              !3
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0  $16     
         22        ASSIGN                                                   !5, $16
   15    23        ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !5, !1
         24      > JMPZ_EX                                          ~18     ~18, ->27
         25    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~19     !2, !1
         26        BOOL                                             ~18     ~19
         27    > > JMPZ                                                     ~18, ->35
   16    28    >   FETCH_DIM_R                                      ~21     !2, !1
         29        INIT_ARRAY                                       ~22     ~21
         30        FETCH_DIM_R                                      ~23     !5, !1
         31        ADD_ARRAY_ELEMENT                                ~22     ~23
         32        ASSIGN_DIM                                               !2, !1
         33        OP_DATA                                                  ~22
         34      > JMP                                                      ->40
   19    35    >   INIT_FCALL                                               'array_merge'
         36        SEND_VAR                                                 !2
         37        SEND_VAR                                                 !5
         38        DO_ICALL                                         $24     
         39        ASSIGN                                                   !2, $24
    9    40    > > JMP                                                      ->9
         41    >   FE_FREE                                                  $10
   24    42      > RETURN                                                   !2
   25    43*     > RETURN                                                   null

End of function coolpluck

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.37 ms | 1403 KiB | 18 Q