3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $path = ""; $finalArray = array(); $sourceArray = array( "bla.tif", "quux.tif", array("foo" => array("bar" => array("lorem" => array("ipsum.tif", "doler.tif")))), array("bar" => array("qux" => array("baz" => array("ipsum.tif", "ufo.tif")))) ); foreach($sourceArray as $key => $value) { if(!is_array($value)) { $finalArray[] = $value; } else { $finalArray[] = recur($value, $path); } } print_r($finalArray); function recur($value, $path) { foreach($value as $idx => $subValue) { if(!is_array($subValue)) { return $path . "/" . $subValue; } else { return recur($subValue, $path . "/" . $idx); } } }
Output for 4.3.0 - 7.1.0
Array ( [0] => bla.tif [1] => quux.tif [2] => /foo/bar/lorem/ipsum.tif [3] => /bar/qux/baz/ipsum.tif )