3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Arr { public static function flatten( $array ) { $flat = array(); foreach ( $array as $key => $value ) { if ( is_array( $value ) ) { $flat += Arr::flatten( $value ); } else { $flat[ $key ] = $value; } } return $flat; } } $sample = array( 'pictures' => array( 'name' => array( 1 => array( 1 => 'Chrysanthemum.jpg', 2 => 'Desert.jpg', ), 2 => array( 1 => '', ), 3 => array( 1 => '', 2 => 'Hydrangeas.jpg', ), ), 'type' => array( 1 => array( 1 => 'image/jpeg', 2 => 'image/jpeg', ), 2 => array( 1 => '', ), 3 => array( 1 => '', 2 => 'image/jpeg', ), ), 'tmp_name' => array( 1 => array( 1 => '/tmp/phpOhzhBd', 2 => '/tmp/phpzFrNjP', ), 2 => array( 1 => '', ), 3 => array( 1 => '', 2 => '/tmp/phpR6hO2q', ), ), 'error' => array( 1 => array( 1 => 0, 2 => 0, ), 2 => array( 1 => 4, ), 3 => array( 1 => 4, 2 => 0, ), ), 'size' => array( 1 => array( 1 => 879394, 2 => 845941, ), 2 => array( 1 => 0, ), 3 => array( 1 => 0, 2 => 595284, ), ), ) ); print_r( $sample ); print_r( Arr::flatten( $sample ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WSPOn
function name:  (null)
number of ops:  11
compiled vars:  !0 = $sample
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, <array>
   96     1        INIT_FCALL                                               'print_r'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   99     4        INIT_FCALL                                               'print_r'
          5        INIT_STATIC_METHOD_CALL                                  'Arr', 'flatten'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $3      
          8        SEND_VAR                                                 $3
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Class Arr:
Function flatten:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/WSPOn
function name:  flatten
number of ops:  18
compiled vars:  !0 = $array, !1 = $flat, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        ASSIGN                                                   !1, <array>
   10     2      > FE_RESET_R                                       $5      !0, ->15
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->15
          4    >   ASSIGN                                                   !3, ~6
   12     5        TYPE_CHECK                                  128          !2
          6      > JMPZ                                                     ~8, ->12
   14     7    >   INIT_STATIC_METHOD_CALL                                  'Arr', 'flatten'
          8        SEND_VAR                                                 !2
          9        DO_FCALL                                      0  $9      
         10        ASSIGN_OP                                     1          !1, $9
         11      > JMP                                                      ->14
   18    12    >   ASSIGN_DIM                                               !1, !3
         13        OP_DATA                                                  !2
   10    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $5
   22    16      > RETURN                                                   !1
   23    17*     > RETURN                                                   null

End of function flatten

End of class Arr.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.06 ms | 1396 KiB | 15 Q