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, ), ), ) ); print_r( $sample ); print_r( Arr::flatten( $sample ) );
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
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 ) ) ) ) Array ( [1] => Chrysanthemum.jpg [2] => 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/WSPOn 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/WSPOn 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/WSPOn on line 6
Process exited with code 255.