文件夹和子文件夹中所有文件的数组,不带路径[重复]

This question already has an answer here:

I have some folder structure like this

/photos/1/file1.txt
/photos/2/file2/txt

What i need is to get inside folder photos and get array of all files without path, final array should look like this

$content = ('file1.txt', 'file2.txt');

This is what i have for now, but still not like with final array

function recursive_scandir($dir){
    $contents = array();
    foreach(scandir($dir) as $file){
        if($file == '.' || $file == '..') continue;
        $path = $dir.DIRECTORY_SEPARATOR.$file;
        if(is_dir($path)){
            $contents = array_merge($contents, recursive_scandir($path));
        } else {
            $contents[] = $path;
        }
    }
    return $contents;
}

print_r(recursive_scandir('photos/'));
</div>

You should search better: Get the hierarchy of a directory with PHP

After you get your file with path like "/photos/1/file1.txt", you can use basename.