I'm trying to optimize performance for recursive directory listing with some exceptions:
function listdir($basedir) {
global $root, $ignore_dirs, $ignore_files, $filetypes, $ignore_starts_with;
if ($handle = @opendir($basedir)) {
while (false !== ($fn = readdir($handle))) {
if ($fn != '.' && $fn != '..') {
$s = true;
foreach ($ignore_starts_with as $pre) if (strpos($fn, $pre) === 0) $s = false;
$dir = $basedir."/".$fn;
if ($s && is_dir($dir) && !in_array($fn, $ignore_dirs)) {
listdir($dir);
} else {
if ($s && !in_array($fn,$ignore_files) && preg_match("/[^.\/].+\.($filetypes)$/",$dir,$fname)) printlink($fname[0]);
}
}
}
closedir($handle);
}
}
$s
variable will only hold the last assignment, so you may as well just break out of it the first time that condition is met. \$\endgroup\$