3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function collapse($path, $collapse, &$result) { foreach($collapse AS $key => $value) { if(is_array($value)) { collapse($path . $key . "/", $value, $result); continue; } $result[] = $path . $value; } } $result = array(); $toCollapse = 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")))) ); collapse("", $toCollapse, $result); print_r($result);
Output for 4.3.0 - 7.1.0
Array ( [0] => bla.tif [1] => quux.tif [2] => 2/foo/bar/lorem/ipsum.tif [3] => 2/foo/bar/lorem/doler.tif [4] => 3/bar/qux/baz/ipsum.tif [5] => 3/bar/qux/baz/ufo.tif )