3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_flatten($array, $allowedKeys = [], $result = []) { if(!is_array($array)) { return false; } foreach($array as $key => $value) { if(is_array($value)) { $result = array_flatten($value, $allowedKeys, $result); } else if(in_array($key, $allowedKeys)) { $result[$key] = $value; } } return $result; } $allowedKeys = [ 'firstname', 'middlename', 'street', 'lastname', 'housenumber', ]; $userdata = [ 'firstname' => 'first', 'middlename' => 'middle', 'lastname' => 'last', 'address' => [ 'street' => 'streeeeeet', 'housenumber' => '10' ] ]; $addresses = array_flatten($userdata, $allowedKeys); var_dump($addresses);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2hHov
function name:  (null)
number of ops:  11
compiled vars:  !0 = $allowedKeys, !1 = $userdata, !2 = $addresses
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   ASSIGN                                                   !0, <array>
   26     1        ASSIGN                                                   !1, <array>
   36     2        INIT_FCALL                                               'array_flatten'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !2, $5
   37     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function array_flatten:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 27
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 27
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 26
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/2hHov
function name:  array_flatten
number of ops:  30
compiled vars:  !0 = $array, !1 = $allowedKeys, !2 = $result, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
          2        RECV_INIT                                        !2      <array>
    3     3        TYPE_CHECK                                  128  ~5      !0
          4        BOOL_NOT                                         ~6      ~5
          5      > JMPZ                                                     ~6, ->7
    4     6    > > RETURN                                                   <false>
    7     7    > > FE_RESET_R                                       $7      !0, ->27
          8    > > FE_FETCH_R                                       ~8      $7, !3, ->27
          9    >   ASSIGN                                                   !4, ~8
    8    10        TYPE_CHECK                                  128          !3
         11      > JMPZ                                                     ~10, ->19
    9    12    >   INIT_FCALL_BY_NAME                                       'array_flatten'
         13        SEND_VAR_EX                                              !3
         14        SEND_VAR_EX                                              !1
         15        SEND_VAR_EX                                              !2
         16        DO_FCALL                                      0  $11     
         17        ASSIGN                                                   !2, $11
         18      > JMP                                                      ->26
   10    19    >   INIT_FCALL                                               'in_array'
         20        SEND_VAR                                                 !4
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $13     
         23      > JMPZ                                                     $13, ->26
   11    24    >   ASSIGN_DIM                                               !2, !4
         25        OP_DATA                                                  !3
    7    26    > > JMP                                                      ->8
         27    >   FE_FREE                                                  $7
   15    28      > RETURN                                                   !2
   16    29*     > RETURN                                                   null

End of function array_flatten

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.78 ms | 1403 KiB | 18 Q