PDA

View Full Version : Creating an array from a while loop


reeksy
11-30-2005, 05:33 PM
Hi

How do you create an array from a while loop? Basically i want to list out all the files within a directory (below)


$dh = opendir($img_dir_1);
while($file = readdir($dh)){
if ($file != '.' && $file != '..' && $file != 'Thumbs.db'){
print ($file)."<br>";
}
}


Then i want to build each $file into an array and randomly select one using the array_rand() function.

However im unsure on how to build my array around the while loop!?!

Thanks for any help!

marek_mar
11-30-2005, 05:58 PM
Instead od printin you add it to an the array.
$files = array();
$dh = opendir($img_dir_1);
while($file = readdir($dh)){
if ($file != '.' && $file != '..' && $file != 'Thumbs.db'){
$files[] = $file;
}
}