My proposal without ugly "foreach" control structures is
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
$allFiles = array_filter(iterator_to_array($iterator), function($file) {
return $file->isFile();
});
You may only want to extract the filepath, which you can do so by:
array_keys($allFiles);
Still 4 lines of code, but more straight forward than using a loop or something.