3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_flatten($array = null) { $result = array(); if (!is_array($array)) { $array = func_get_args(); } foreach ($array as $key => $value) { if (is_array($value)) { $result = array_merge($result, array_flatten($value)); } else { $result = array_merge($result, array($key => $value)); } } return $result; } $myarray = array('a', ['bla' => 0], 'b',[0,1], [0=>7], array(array(array('x'), 'y', 'z')), array(array('p'))); $res = array_flatten($myarray); var_dump( $res); $string_res = array_flatten( 'cramp' ); var_dump( $string_res );
Output for git.master, git.master_jit, rfc.property-hooks
array(10) { [0]=> string(1) "a" ["bla"]=> int(0) [1]=> string(1) "b" [2]=> int(0) [3]=> int(1) [4]=> int(7) [5]=> string(1) "x" [6]=> string(1) "y" [7]=> string(1) "z" [8]=> string(1) "p" } array(1) { [0]=> string(5) "cramp" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
70.37 ms | 402 KiB | 8 Q