3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function arrayFlat($arr){ $out = ''; foreach($arr as $key => $value){ if(!is_array($value)){ $out .= $value.','; }else{ $out .= $key.','; $out .= arrayFlat($value); } } return trim($out,','); } $aNonFlat = array( 1, 2, array( 3, 4, 5, array( 6, 7 ), 8, 9, ), 10, 11 ); $result = explode(',',arrayFlat($aNonFlat)); echo '<pre>'; print_r($result); echo '</pre>';
based on 7cO9N
Output for 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.30 - 7.2.7
<pre>Array ( [0] => 1 [1] => 2 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 3 [7] => 6 [8] => 78 [9] => 910 [10] => 11 ) </pre>