3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_flatten($array, $result = []) { if(!is_array($array)) { return false; } foreach($array as $key => $value) { if(is_array($value)) { $result = array_flatten($value, $result); } else { $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); foreach($userdata as $key => $value) { if(!in_array($key, $allowedKeys)) { unset($userdata[$key]); } } var_dump($addresses);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/TqgFA
function name:  (null)
number of ops:  22
compiled vars:  !0 = $allowedKeys, !1 = $userdata, !2 = $addresses, !3 = $value, !4 = $key
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        DO_FCALL                                      0  $7      
          5        ASSIGN                                                   !2, $7
   38     6      > FE_RESET_R                                       $9      !1, ->17
          7    > > FE_FETCH_R                                       ~10     $9, !3, ->17
          8    >   ASSIGN                                                   !4, ~10
   39     9        INIT_FCALL                                               'in_array'
         10        SEND_VAR                                                 !4
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $12     
         13        BOOL_NOT                                         ~13     $12
         14      > JMPZ                                                     ~13, ->16
   40    15    >   UNSET_DIM                                                !1, !4
   38    16    > > JMP                                                      ->7
         17    >   FE_FREE                                                  $9
   44    18        INIT_FCALL                                               'var_dump'
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

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

End of function array_flatten

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.59 ms | 1403 KiB | 18 Q