3v4l.org

run code in 300+ PHP versions simultaneously
<?php function flatten_array($array, $flat = array()) { foreach($array as $k=>$v){ if(!is_array($v)){ while(true){ $i = isset($i) ? $i+1 : 0; $key = "$k$i"; if(!array_key_exists($key, $flat)) break; } $flat[$key] = $v; unset($array[$k]); }else{ $flat = flatten_array($v, $flat); } } return $flat; } $a = array_fill(0, 10, array_fill(0, 10, 0)); $array = flatten_array($a); var_dump($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3l5rF
function name:  (null)
number of ops:  19
compiled vars:  !0 = $a, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'array_fill'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 10
          3        INIT_FCALL                                               'array_fill'
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 10
          6        SEND_VAL                                                 0
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                         $3      
         10        ASSIGN                                                   !0, $3
   21    11        INIT_FCALL                                               'flatten_array'
         12        SEND_VAR                                                 !0
         13        DO_FCALL                                      0  $5      
         14        ASSIGN                                                   !1, $5
   22    15        INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Function flatten_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 34
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 34
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 28
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 9
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 23
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
Branch analysis from position: 23
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/3l5rF
function name:  flatten_array
number of ops:  37
compiled vars:  !0 = $array, !1 = $flat, !2 = $v, !3 = $k, !4 = $i, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    4     2      > FE_RESET_R                                       $6      !0, ->34
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->34
          4    >   ASSIGN                                                   !3, ~7
    5     5        TYPE_CHECK                                  128  ~9      !2
          6        BOOL_NOT                                         ~10     ~9
          7      > JMPZ                                                     ~10, ->28
    6     8    > > JMP                                                      ->23
    7     9    >   ISSET_ISEMPTY_CV                                         !4
         10      > JMPZ                                                     ~11, ->14
         11    >   ADD                                              ~12     !4, 1
         12        QM_ASSIGN                                        ~13     ~12
         13      > JMP                                                      ->15
         14    >   QM_ASSIGN                                        ~13     0
         15    >   ASSIGN                                                   !4, ~13
    8    16        NOP                                                      
         17        FAST_CONCAT                                      ~15     !3, !4
         18        ASSIGN                                                   !5, ~15
    9    19        ARRAY_KEY_EXISTS                                 ~17     !5, !1
         20        BOOL_NOT                                         ~18     ~17
         21      > JMPZ                                                     ~18, ->23
         22    > > JMP                                                      ->24
    6    23    > > JMPNZ                                                    <true>, ->9
   11    24    >   ASSIGN_DIM                                               !1, !5
         25        OP_DATA                                                  !2
   12    26        UNSET_DIM                                                !0, !3
         27      > JMP                                                      ->33
   14    28    >   INIT_FCALL_BY_NAME                                       'flatten_array'
         29        SEND_VAR_EX                                              !2
         30        SEND_VAR_EX                                              !1
         31        DO_FCALL                                      0  $20     
         32        ASSIGN                                                   !1, $20
    4    33    > > JMP                                                      ->3
         34    >   FE_FREE                                                  $6
   17    35      > RETURN                                                   !1
   18    36*     > RETURN                                                   null

End of function flatten_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.35 ms | 1403 KiB | 18 Q