Jump to content

array_multisort help


gamer

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.