3v4l.org

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

End of function coolpluck

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.46 ms | 1394 KiB | 18 Q