3v4l.org

run code in 300+ PHP versions simultaneously
<?php function flatten($arr) { $result = array(); foreach ($arr as $key => $value) { if (is_array($value)) { foreach (flatten($value) as $subKey => $scalar) { $result[$key . ':' . $subKey] = $scalar; } } else if (is_scalar($value)) { $result[$key] = $value; } } return $result; } var_dump(flatten(['foo' => 123, 'bar' => 456])); var_dump(flatten(['foo' => ['bar' => 123, 'baz' => 456]]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fGrI8
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'flatten'
          2        SEND_VAL                                                 <array>
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   21     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'flatten'
          8        SEND_VAL                                                 <array>
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

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

End of function flatten

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.93 ms | 1403 KiB | 17 Q