3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = [ 'owner' => [ 'table' => 'owner', 'cols' => [ 'name' => 'Name', 'address' => [ 'table' => 'Address', 'cols' => [ 'line1' => 'Street Line 1', 'line2' => 'Street Line 2', 'city' => 'City', 'state' => [ 'table' => 'State', 'cols' => [ 'stateName' => 'State' ] ], 'postal_code' => 'Postal Code', ] ] ] ], 'renter' => [ 'table' => 'renter', 'cols' => [ 'name' => 'Name', 'address' => [ 'table' => 'Address', 'cols' => [ 'line1' => 'Street Line 1', 'line2' => 'Street Line 2', 'city' => 'City', 'state' => [ 'table' => 'State', 'cols' => [ 'stateName' => 'State' ] ], 'postal_code' => 'Postal Code', ] ] ] ] ]; function flatten(array $a, string $path = '') { if (isset($a['cols'])) { return flatten($a['cols'], $path); } $pairs = []; foreach ($a as $k => $v) { $p = empty($path) ? $k : "{$path}.{$k}"; if (is_array($v)) { array_push($pairs, ...flatten($v, $p)); } else { $pairs[] = ["key" => $p, "label" => $v]; } } return $pairs; } var_dump(flatten($a)); /* [ [ 'key' => 'owner.name', 'label' => 'Name' ], [ 'key' => 'owner.address.line1', 'label' => 'Street Line 1' ], [ 'key' => 'owner.address.line2', 'label' => 'Street Line 2' ], [ 'key' => 'owner.address.city', 'label' => 'City' ], [ 'key' => 'owner.address.state.stateName', 'label' => 'State' ], [ 'key' => 'owner.address.postal_code', 'label' => 'Postal Code' ], ] */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FqDT7
function name:  (null)
number of ops:  8
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   66     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'flatten'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
   95     7      > RETURN                                                   1

Function flatten:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 41
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 41
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 36
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 36
Branch analysis from position: 26
Branch analysis from position: 36
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/FqDT7
function name:  flatten
number of ops:  44
compiled vars:  !0 = $a, !1 = $path, !2 = $pairs, !3 = $v, !4 = $k, !5 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
   50     2        ISSET_ISEMPTY_DIM_OBJ                         0          !0, 'cols'
          3      > JMPZ                                                     ~6, ->11
   51     4    >   INIT_FCALL_BY_NAME                                       'flatten'
          5        CHECK_FUNC_ARG                                           
          6        FETCH_DIM_FUNC_ARG                               $7      !0, 'cols'
          7        SEND_FUNC_ARG                                            $7
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0  $8      
         10      > RETURN                                                   $8
   54    11    >   ASSIGN                                                   !2, <array>
   55    12      > FE_RESET_R                                       $10     !0, ->41
         13    > > FE_FETCH_R                                       ~11     $10, !3, ->41
         14    >   ASSIGN                                                   !4, ~11
   56    15        ISSET_ISEMPTY_CV                                         !1
         16      > JMPZ                                                     ~13, ->19
         17    >   QM_ASSIGN                                        ~14     !4
         18      > JMP                                                      ->23
         19    >   ROPE_INIT                                     3  ~16     !1
         20        ROPE_ADD                                      1  ~16     ~16, '.'
         21        ROPE_END                                      2  ~15     ~16, !4
         22        QM_ASSIGN                                        ~14     ~15
         23    >   ASSIGN                                                   !5, ~14
   57    24        TYPE_CHECK                                  128          !3
         25      > JMPZ                                                     ~19, ->36
   58    26    >   INIT_FCALL                                               'array_push'
         27        SEND_REF                                                 !2
         28        INIT_FCALL_BY_NAME                                       'flatten'
         29        SEND_VAR_EX                                              !3
         30        SEND_VAR_EX                                              !5
         31        DO_FCALL                                      0  $20     
         32        SEND_UNPACK                                              $20
         33        CHECK_UNDEF_ARGS                                         
         34        DO_ICALL                                                 
         35      > JMP                                                      ->40
   60    36    >   INIT_ARRAY                                       ~23     !5, 'key'
         37        ADD_ARRAY_ELEMENT                                ~23     !3, 'label'
         38        ASSIGN_DIM                                               !2
         39        OP_DATA                                                  ~23
   55    40    > > JMP                                                      ->13
         41    >   FE_FREE                                                  $10
   63    42      > RETURN                                                   !2
   64    43*     > RETURN                                                   null

End of function flatten

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.97 ms | 1394 KiB | 18 Q