3v4l.org

run code in 300+ PHP versions simultaneously
<?php function flatten_array($array, $flat = array()) { foreach($array as $k=>$v){ $k = strval($k); if(!is_array($v)){ $i = 0; while(true){ $i++; $key = $k.strval($i); if(!isset($flat[$key])) break; } unset($i); $flat[$key] = $v; unset($array[$k]); }else{ $flat = flatten_array($v, $flat); unset($array[$k]); } } 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/trIGG
function name:  (null)
number of ops:  19
compiled vars:  !0 = $a, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     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
   25    11        INIT_FCALL                                               'flatten_array'
         12        SEND_VAR                                                 !0
         13        DO_FCALL                                      0  $5      
         14        ASSIGN                                                   !1, $5
   26    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 = 10, Position 2 = 26
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 12
Branch analysis from position: 21
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: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 20
Branch analysis from position: 26
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/trIGG
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        CAST                                          6  ~9      !3
          6        ASSIGN                                                   !3, ~9
    6     7        TYPE_CHECK                                  128  ~11     !2
          8        BOOL_NOT                                         ~12     ~11
          9      > JMPZ                                                     ~12, ->26
    7    10    >   ASSIGN                                                   !4, 0
    8    11      > JMP                                                      ->20
    9    12    >   PRE_INC                                                  !4
   10    13        CAST                                          6  ~15     !4
         14        CONCAT                                           ~16     !3, ~15
         15        ASSIGN                                                   !5, ~16
   11    16        ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !1, !5
         17        BOOL_NOT                                         ~19     ~18
         18      > JMPZ                                                     ~19, ->20
         19    > > JMP                                                      ->21
    8    20    > > JMPNZ                                                    <true>, ->12
   13    21    >   UNSET_CV                                                 !4
   14    22        ASSIGN_DIM                                               !1, !5
         23        OP_DATA                                                  !2
   15    24        UNSET_DIM                                                !0, !3
         25      > JMP                                                      ->32
   17    26    >   INIT_FCALL_BY_NAME                                       'flatten_array'
         27        SEND_VAR_EX                                              !2
         28        SEND_VAR_EX                                              !1
         29        DO_FCALL                                      0  $21     
         30        ASSIGN                                                   !1, $21
   18    31        UNSET_DIM                                                !0, !3
    4    32    > > JMP                                                      ->3
         33    >   FE_FREE                                                  $6
   21    34      > RETURN                                                   !1
   22    35*     > RETURN                                                   null

End of function flatten_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.74 ms | 1402 KiB | 18 Q