3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Flatten a multi-dimensional array to a single-level array, * sorting the entries in order to depth first. * * @param array $carry Optional Array to initialize * @param mixed $subject Array or value that has data in potential multi-dimensions. * * @return array */ function array_flatten(?array $carry = [], $subject): array { return array_reduce((array) $subject, function(array $carry, $item) { return is_array($item) ? array_flatten($carry, $item) : array_merge($carry, (array) $item); }, (array) $carry); } print_r(array_flatten(null, array( array('A', array('B', array('CC','CCCC','CCCCCC'), array('DDD','EFG','HIJ','LMNOP') ) ), array('2'), 'b', array(array(),array(),array()), ))); $array = array(1,2,[3,4],5,'six',array(array('78',9)),10); print_r(array_reduce($array, "array_flatten"));
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Optional parameter $carry declared before required parameter $subject is implicitly treated as a required parameter in /in/J1NeJ on line 12 Array ( [0] => A [1] => B [2] => CC [3] => CCCC [4] => CCCCCC [5] => DDD [6] => EFG [7] => HIJ [8] => LMNOP [9] => 2 [10] => b ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => six [6] => 78 [7] => 9 [8] => 10 )

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:
63.06 ms | 402 KiB | 8 Q