Php Foreach With Multidimensional Array Folders

Posted on
  1. Php Print Multidimensional Array
  2. Php Foreach With Multidimensional Array Folders Free
  3. Multi Dimensional Array Examples

Use marraykeyexists as above to check one level deeper than arraykeyexists whether an array key exists in arrays like you've shown. If your rules aren't as simple as I've thought they are, it sounds to me like you want to loop through your second array, check for array keys, apply your special rules and add the result to the third array.

I need to store all directories and files in multidimensional array for a given location (sample : /path/to/folder) . It should include the sub folders as well no matter how deep.

Edited : Morris from america movie review.

Php Print Multidimensional Array

I tried with php scandir and it gave me following results,

code :

results :

Php Foreach With Multidimensional Array Folders Free

What I need is to get the content inside the folder1 and do it continuously till I get complete folder structure with all files.

P.S : I need to remove '.' and '.' from the result array too.

Janith Chinthana

Multi Dimensional Array Examples

Janith ChinthanaJanith Chinthana
2,7562 gold badges18 silver badges44 bronze badges

1 Answer

Multidimensional

for file listing php provide readdir and scandir functions.

I preferred sccandir since it's new(php 5>) and we can use following recursive function for this.

Need to provide the directory path (/path/to/your/folder) as a parameter and it will return multidimensional array with folder structure.

Janith ChinthanaJanith Chinthana
2,7562 gold badges18 silver badges44 bronze badges
Php Foreach With Multidimensional Array Folders
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged phpdirectoryiteration or ask your own question.