gamer Posted July 24, 2008 Share Posted July 24, 2008 Hello, I am new to the boards here and to PHP. I am trying to get a list of files from a folder based on date criteria. I have managed to get all of the files that I need and get them into a readable order, but I am having trouble sorting them. I am not sure where I am going wrong, I can sort them by file name, but cannot seem to figure out how to then sort them by date modified. Thanks for any help. <?PHP //todays date $Now = date('F d Y'); //a few weeks ago $past = time() - (27 * 24 * 60 * 60); //print out today's date under title echo "Today's Date: $Now "; //some spaces print"<br><br><br>"; //initialize directory name $dirname = "schedules"; //open directory if ($folder = opendir($dirname)) { //create arrays $filesArray = array(); $modTime = array(); //read directory while (false !== ($file = readdir($folder))) { //only get files that are in date range if(filemtime($dirname."/".$file) > ($past)){ //do not get folders if ($file != "." && $file != ".."){ // Add each file to array $modTime[] = filemtime($dirname."/".$file); $filesArray[] = ($file); } } } //sort arrays array_multisort($filesArray, SORT_ASC, $modTime, SORT_DESC); //array for stores $stores = array('001', '002', '002', '004', '005', '006', '007', '008', '009', '010', '011'); //output $st = 0; foreach ($filesArray as $file) {; //date file modified $timestamp = date("m d Y",filemtime($dirname."/".$file)); //just show the store number part of the file name $string=substr($file, 0, 3); //if does not equal store number then print the table header if($st <> $string){ print"<table width='500' border='1'> <tr><td colspan='2'><b>Store ".$string."</b></td></tr> <tr><td>Date Submitted</td><td>Schedule Link</tr></td><br>"; $st = $string; } //if equals store number then print out the data if($st == $string){ print"<tr><td>$timestamp</td><td><a href='schedules/".$file."'>$string</a></td></tr>"; } } print"</table>"; closedir($folder); } ?> [code] [/code] Link to comment https://forums.phpfreaks.com/topic/116485-array_multisort-help/ Share on other sites More sharing options...
gamer Posted July 28, 2008 Author Share Posted July 28, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/116485-array_multisort-help/#findComment-601703 Share on other sites More sharing options...
samshel Posted July 28, 2008 Share Posted July 28, 2008 you want to sort files on modified dates? try this.. array_multisort($modTime, SORT_DESC, $filesArray, SORT_DESC); Link to comment https://forums.phpfreaks.com/topic/116485-array_multisort-help/#findComment-601717 Share on other sites More sharing options...
gamer Posted July 28, 2008 Author Share Posted July 28, 2008 I am trying to sort the files first by the file name that I have substringed and then by the modified date, while I can sort the $filesArray ascending, I have not been able to then sort the $modTime descending. thanks for your reply, Wade Link to comment https://forums.phpfreaks.com/topic/116485-array_multisort-help/#findComment-601732 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.