I've written the below function, but fileList is blank when echoed out. Any ideas why this might be happening? and how to fix it?
function testing($dir){
echo $dir;
$fileList=array();
function recursiveScan($dir) {
$tree = glob(rtrim($dir, '/') . '/*');
if (is_array($tree)) {
foreach($tree as $file) {
if (is_dir($file)) {
echo $file . '('.filemtime($file).')'.'<br/>';
recursiveScan($file);
$fileList[date('YmdHis',filemtime($file))]=$file;
} elseif (is_file($file)) {
echo $file . '('.filemtime($file).')'.'<br/>';
$fileList[date('YmdHis',filemtime($file))]=$file;
}
}
?>
<pre>
<?php print_r($fileList);?>
</pre>
<?php
}
}
}
EDIT:
If I move the print_r bit of the code below up a few } then it outputs... but I want to output it once all directories have been searched through.
function recursiveScan($dir) {
$tree = glob(rtrim($dir, '/') . '/*');
if (is_array($tree)) {
foreach($tree as $file) {
if (is_dir($file)) {
echo $file . '('.filemtime($file).')'.'<br/>';
recursiveScan($file);
$fileList[date('YmdHis',filemtime($file))]=$file;
} elseif (is_file($file)) {
echo $file . '('.filemtime($file).')'.'<br/>';
$fileList[date('YmdHis',filemtime($file))]=$file;
}
}
}
?>
<pre>
<?php print_r($fileList);?>
</pre>
<?php
}