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])) { if (!isset($output[$keyToFind])) { $output[$keyToFind] = $results[$keyToFind]; } else { if (is_array($output[$keyToFind])) { $output[$keyToFind] = array_merge(array($output[$keyToFind]), $results[$keyToFind]); } else { $output[$keyToFind] = array_merge((array)$output[$keyToFind], (array)$results[$keyToFind]); } } } } } } return $output; } $testArray = array( 'test' => array( 'percy' => array( 'percy' => array('percy' => 'anderson') ), 'mitch' => array( 'mitchell', 'anderson' ) ) ); var_dump(coolPluck($testArray, array('percy', 'mitch')));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eimuj
function name:  (null)
number of ops:  9
compiled vars:  !0 = $testArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   ASSIGN                                                   !0, <array>
   52     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 = 54
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 54
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 52
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 52
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 = 51
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 51
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 41
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 51
Branch analysis from position: 51
Branch analysis from position: 12
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 52
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
filename:       /in/eimuj
function name:  coolPluck
number of ops:  57
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, ->54
          4    > > FE_FETCH_R                                               $8, !3, ->54
    8     5    > > FE_RESET_R                                       $9      !0, ->52
          6    > > FE_FETCH_R                                       ~10     $9, !4, ->52
          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, ->51
   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, ->51
   17    21    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !2, !3
         22        BOOL_NOT                                         ~19     ~18
         23      > JMPZ                                                     ~19, ->28
   18    24    >   FETCH_DIM_R                                      ~21     !6, !3
         25        ASSIGN_DIM                                               !2, !3
         26        OP_DATA                                                  ~21
         27      > JMP                                                      ->51
   21    28    >   FETCH_DIM_R                                      ~22     !2, !3
         29        TYPE_CHECK                                  128          ~22
         30      > JMPZ                                                     ~23, ->41
   23    31    >   INIT_FCALL                                               'array_merge'
         32        FETCH_DIM_R                                      ~25     !2, !3
         33        INIT_ARRAY                                       ~26     ~25
         34        SEND_VAL                                                 ~26
         35        FETCH_DIM_R                                      ~27     !6, !3
         36        SEND_VAL                                                 ~27
         37        DO_ICALL                                         $28     
         38        ASSIGN_DIM                                               !2, !3
         39        OP_DATA                                                  $28
         40      > JMP                                                      ->51
   25    41    >   INIT_FCALL                                               'array_merge'
         42        FETCH_DIM_R                                      ~30     !2, !3
         43        CAST                                          7  ~31     ~30
         44        SEND_VAL                                                 ~31
         45        FETCH_DIM_R                                      ~32     !6, !3
         46        CAST                                          7  ~33     ~32
         47        SEND_VAL                                                 ~33
         48        DO_ICALL                                         $34     
         49        ASSIGN_DIM                                               !2, !3
         50        OP_DATA                                                  $34
    8    51    > > JMP                                                      ->6
         52    >   FE_FREE                                                  $9
    7    53      > JMP                                                      ->4
         54    >   FE_FREE                                                  $8
   35    55      > RETURN                                                   !2
   36    56*     > RETURN                                                   null

End of function coolpluck

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.06 ms | 1402 KiB | 18 Q