Display `pretty output` of directory content from array
- by user275074
Hi,
I'm using the following code to get an array of directories and their sub-directories where each contain file type extension: png. It works great but I need to be able to output the results of the array in a list style format e.g.
Test
- test2.png
- test1.png
subfolder
- test3.png
sub sub folder
- test4.png
etc
Code:
$filter=".png";
$directory='../test';
$it=new RecursiveDirectoryIterator("$directory");
foreach(new RecursiveIteratorIterator($it) as $file){
if(!((strpos(strtolower($file),$filter))===false)||empty($filter)){
$items[]=preg_replace("#\\\#", "/", $file);
}
}
Example array of results:
array (
0 => '../test/test2.png',
1 => '../test/subfolder/subsubfolder/test3.png',
2 => '../test/subfolder/test3.png',
3 => '../test/test1.png',
)
What would be the best way of achieving the desired result?