3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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, ), ), ) ); var_dump( $sample ); var_dump( Arr::flatten( $sample ) );
Output for 5.0.0 - 7.1.0
array(1) { ["pictures"]=> array(5) { ["name"]=> array(3) { [1]=> array(2) { [1]=> string(17) "Chrysanthemum.jpg" [2]=> string(10) "Desert.jpg" } [2]=> array(1) { [1]=> string(0) "" } [3]=> array(2) { [1]=> string(0) "" [2]=> string(14) "Hydrangeas.jpg" } } ["type"]=> array(3) { [1]=> array(2) { [1]=> string(10) "image/jpeg" [2]=> string(10) "image/jpeg" } [2]=> array(1) { [1]=> string(0) "" } [3]=> array(2) { [1]=> string(0) "" [2]=> string(10) "image/jpeg" } } ["tmp_name"]=> array(3) { [1]=> array(2) { [1]=> string(14) "/tmp/phpOhzhBd" [2]=> string(14) "/tmp/phpzFrNjP" } [2]=> array(1) { [1]=> string(0) "" } [3]=> array(2) { [1]=> string(0) "" [2]=> string(14) "/tmp/phpR6hO2q" } } ["error"]=> array(3) { [1]=> array(2) { [1]=> int(0) [2]=> int(0) } [2]=> array(1) { [1]=> int(4) } [3]=> array(2) { [1]=> int(4) [2]=> int(0) } } ["size"]=> array(3) { [1]=> array(2) { [1]=> int(879394) [2]=> int(845941) } [2]=> array(1) { [1]=> int(0) } [3]=> array(2) { [1]=> int(0) [2]=> int(595284) } } } } array(2) { [1]=> string(17) "Chrysanthemum.jpg" [2]=> string(10) "Desert.jpg" }
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/b0dPn on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/b0dPn on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/b0dPn on line 6
Process exited with code 255.