Foreach statements. Returns error if no match.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Trenchant
Forum Contributor
Posts: 291
Joined: Mon Nov 29, 2004 6:04 pm
Location: Web Dummy IS

Foreach statements. Returns error if no match.

Post by Trenchant »

I have made a php file manager and in one part I'm using foreach to look for files. The only problem is that if there are no files in a folder(if none have been added yet) then the foreach statement leaves an error. I don't want it to leave an error.

Is there any way to disable it from leaving an error if it doesn't read anything? I don't want to disable errors for the whole page.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

count the number of files in folder. if number is greater than 0 execute for each loop else go to the next folder.
Post Reply