Skip to content

Instantly share code, notes, and snippets.

@robotamer
Created July 13, 2012 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robotamer/3107221 to your computer and use it in GitHub Desktop.
Save robotamer/3107221 to your computer and use it in GitHub Desktop.
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