I am trying to make recursive PHP function which will loop through tree of directories and subdirectories and put all directories and files in one array.
My code looks logical to me, but it is not working.
Tree of directories and files:
PHP code
<?php
function printFiles($directory) {
$files = array();
foreach (scandir($directory) as $file) {
if ($file === '.' || $file === '..')
continue;
// checking is it file or directory
if (is_dir($directory . '\\'. $file)) {
return printFiles($directory . '\\'. $file);
}
array_push($files, $file);
}
return($files);
}
$directory = 'C:\Users\Jakov\Desktop\DIRECTORIES';
print_r(printFiles($directory));
?>
I am getting this result:
Array ( )

if (is_dir($directory . '\\'. $file));.