Sure this is a oversight, My Function is to search directories looking for a filename.
Save to an array for use in another part of the program.
Function works fine, however the results never return outside of the function. I can print the results fine within the function, But this is no use as i need to use this later on. Is there any reason why this is happening?
<?php
function search_file($dir,$file_to_search){
$files = scandir($dir);
foreach($files as $key => $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if(!is_dir($path)) {
if($file_to_search == $value){
$resultfind[] = $path;
}
} else if($value != "." && $value != "..") {
search_file($path, $file_to_search);
}
}
print_r ($resultfind) ;
return $resultfind ;
}
$file_to_search = "SessionLock.txt";
$searchResults = search_file('.',$file_to_search);
echo "The Returned Results are <br> " ;
print_r ($searchResults) ;