$dirs = array(
'foo',
'bar/baz',
'some/dir',
);
foreach ($dirs as $dir) {
// put your code here
}
but if you want an easy way to search a directory, and all directories inside of that directory, you want a recursive function
heres a sample.
function scandir_r_search($dir, $substring)
{
$filenames = array();
if (!is_dir($dir) || !is_readable($dir)) {
return false;
}
if ($handle = opendir($dir)) {
while (false !== ($filename = readdir($handle))) {
if ($filename === '.' || $filename === '..') continue;
if (is_dir("$dir/$filename")) {
$nested_filenames = scandir_r_search("$dir/$filename", $substring);
if (is_array($nested_filenames)) {
$filenames = array_merge($filenames, $nested_filenames);
}
} else {
if (false !== strpos($filename, $substring)) {
$filenames[] = "$dir/$filename";
}
}
}
closedir($handle);
}
return $filenames;
}
print_r(scandir_r_search('.', '.php')); // find all filenames that contain .php
that will return all the files in a single dimension array. if you want the files grouped by thier specific dir in a multidim array, youd need to modify it a tiny bit. you can read the manual to see more examples given by users.
btw- i found it comical that the above function is faster than the built in search utility in winxp.
it was still alot faster even when i made the function case insensitive :p