3v4l.org

run code in 300+ PHP versions simultaneously
<?php function flatten_array(array $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/qNXeZ
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 = 33
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 33
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 27
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 9
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
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 = 21, Position 2 = 22
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 22
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
Branch analysis from position: 22
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/qNXeZ
function name:  flatten_array
number of ops:  36
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, ->33
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->33
          4    >   ASSIGN                                                   !3, ~7
    5     5        TYPE_CHECK                                  128  ~9      !2
          6        BOOL_NOT                                         ~10     ~9
          7      > JMPZ                                                     ~10, ->27
    6     8    > > JMP                                                      ->22
    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        CONCAT                                           ~15     !3, !4
         17        ASSIGN                                                   !5, ~15
    9    18        ARRAY_KEY_EXISTS                                 ~17     !5, !1
         19        BOOL_NOT                                         ~18     ~17
         20      > JMPZ                                                     ~18, ->22
         21    > > JMP                                                      ->23
    6    22    > > JMPNZ                                                    <true>, ->9
   11    23    >   ASSIGN_DIM                                               !1, !5
         24        OP_DATA                                                  !2
   12    25        UNSET_DIM                                                !0, !3
         26      > JMP                                                      ->32
   14    27    >   INIT_FCALL_BY_NAME                                       'flatten_array'
         28        SEND_VAR_EX                                              !2
         29        SEND_VAR_EX                                              !1
         30        DO_FCALL                                      0  $20     
         31        ASSIGN                                                   !1, $20
    4    32    > > JMP                                                      ->3
         33    >   FE_FREE                                                  $6
   17    34      > RETURN                                                   !1
   18    35*     > RETURN                                                   null

End of function flatten_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.52 ms | 1402 KiB | 18 Q