PDA

View Full Version : converting to array



rapier_gv
May 14th, 2007, 03:09 PM
hi all, i'm not much of a php guru, so here's my question
i have created a very basic script which shows the content of a certain directory like so


if ($myDir = opendir('.')) {

while (false !== ($file = readdir($myDir))) {
if ($file != "." && $file != "..") {
echo "$file<br />\n";

}
}
closedir($myDir);
}and now the silly and probably noobish question: how can i convert the list of contents from the directory to an array?

thanks

eirche
May 14th, 2007, 07:16 PM
just use this

$files = array();
foreach (false !== ($file = readdir($myDir))) {
if ($file != "." && $file != "..") {
$files[] = $file;
}
}

rapier_gv
May 15th, 2007, 08:44 AM
lots of thanks! now i can get on with my work:beam: