Organize folders, subfolders, and files in an array?

2

Well, I have an array with values:

array("Pasta/Readme.txt", "Pasta/Subpasta/helloworld.mp3", "Pasta-2/screenshot.png");

How do I return an array like this:

array("Pasta" => array("Readme.txt", "Subpasta" => array("helloworld.mp3")), "Pasta-2" => array("screenshot.png"))

Thank you in advance:)

    
asked by anonymous 27.12.2014 / 21:40

2 answers

1

Considering that you will always have this hierarchy: m folders with n files within each of them and no subfolder:

26.12.2014 / 23:38
0

For each folder, you can run a scandir () to fetch your files

See link

You can also do this with DirectoryIterator. See link

    
27.12.2014 / 02:20