Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Get php files in dir with recursive lambda callback function
<?php
/**
*
* @param string $dir
* @return array
*/
function get_php_files_in_dir($dir)
{
$bin = array ();
$run = function(&$run, $dir, &$bin) {
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (strpos($file, '.php') > 0) {
$bin[] = $dir . '/' . $file;
} elseif (is_dir($dir . '/' . $file)) {
$run($run, $dir . '/' . $file, $bin);
}
}
}
}
closedir($handle);
};
$run($run, $dir, $bin);
return $bin;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment