Hi guys ! I'm new here and to php/programming in general. I've had a class in C before and I'm catching on to php. So here's my problem, I'm trying to make this script that will read files from a directory and list them with the most recently modified file at the top. I found some code online and got it to list my files. Here it is:
<?php
if ($handle = opendir('comics/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
print('<div id="comicList"><a href="comics/'.$file .'" target=_blank >'. substr($file, 0, -4).'</a></div>' . "\n");
}
}
closedir($handle);
}
?>
I've seen a lot of variations of this sort of code here on this forum. Anywho, I added to it to try to list it in order of most recently modified but it doesn't seem to work. Where have I gone wrong ? Anyone kind to explain. Here's the code:
<?php
if ($handle = opendir('comics/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$modified = date( " F j Y h:i:s A" , filemtime($file));
$timeKey[] = $modified;
$fileArray[] = $file;
$bigArray = array ($timeKey, $fileArray);
}
}
closedir($handle);
}
rsort($bigArray[0]);
foreach ($bigArray[1] as $nfile){
print('<div id="comicList"><a href="comics/'.$nfile .'" target=_blank >'. substr($nfile, 0, -4).'</a></div>' . "\n");
}
?>
My understanding is that if I sort $bigArray[0], it'll sort $bigArray[1] in that order as well ? or is that a horribly wrong assumption ? Any help would be most appreciated, thanks guys.