Page 1 of 1

Inlcude files in a loop, with variable as file name?

Posted: Fri Nov 10, 2006 8:32 am
by Kadanis
I'm a bit of a PHP noob. Been using it for about 9 months and still learning so sorry if this is stoopid ;)

my question is, is it possible to iterate over includes like in the below example

Code: Select all

for ($a = 0; $a < 10; $a++){
 include_once("file$a.php");
}
the reason i ask is that some code i'm working on needs profiles and i'd like to store them in separate files for easy maintanence. the thing is that more profiles could be added on an ad hoc basis as they are required and i don't want to have to edit the main code every time one is added.

thanks in advance for help/advice

Posted: Fri Nov 10, 2006 10:04 am
by Oren
Yes, it is possible.

Posted: Fri Nov 10, 2006 11:41 am
by John Cartwright
you might be interested in file_exists()

Posted: Tue Nov 14, 2006 5:58 am
by Kadanis
thanks for the replies. and yes, i'll be using file_exists to make sure that the file is there before including ;)