Sort My Array, by date?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Blyant
Forum Newbie
Posts: 12
Joined: Fri Sep 30, 2005 8:14 am

Sort My Array, by date?

Post by Blyant »

I'm using this code that I put to gether to list the files in a directory on my server, it works just how I want it except that it returns the list of files in Numerical and alphabetical order. How do I sort the file list into the date order, the files were added to the server?

Code: Select all

<?php
echo "<?xml version=\"1.0\" encoding =\"ISO-8859-1\" ?>\n";
echo "<images>\n";
if ($handle = opendir('images')) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
			list($width, $height) = getimagesize("images/".$file);
			echo "<myImage myPath=\"images/" . "$file\"" . " myWidth=\"" . "$width\"" . " myHeight=\"". "$height\"" ." />\n";
       }
   }
   closedir($handle);
}
echo "</images>\n"

?>
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Hi,

Use filectime() to get the time/date the file was created (this should also cover time of addition I think, as it is 'created'), also see fileatime and filemtime linked of the left of that there page.

HTH :)
Blyant
Forum Newbie
Posts: 12
Joined: Fri Sep 30, 2005 8:14 am

Post by Blyant »

I'll give it ago, thank you for the help.
Post Reply