sorting array question
| From: | Javier Montserat | Date: | Tue, 03 Sep 2002 10:27:53 +0000 |
| Subject: | sorting array question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-115005@lists.php.net to get a copy of this message | ||
i have the following code which reads a list of files from a directory -
$listcmd = "ls " .$dirPath;
$temp = exec($listcmd, $listoffiles, $status);
if($status == 0) {
for ($i =0; $i < sizeof($listoffiles); $i++) {
$this->fileName[$i] = $listoffiles[$i];
$this->sizeofFile[$i] = sprintf("%01.2f", (filesize($dirPath."/".$listoffiles[$i])/1024)/1024);
$this->fileDate[$i] = date("d-M-y H:i", filemtime($dirPath."/".$listoffiles[$i]));
}
$this->displayFiles();
What I want to do is display the files sorted by date.
Okay, so I've just realised that the really easy way to do this is by adding -St (sort by time) to the ls command...
$listcmd = "ls -St " .$dirPath;
But how could this be achieved by sorting the three arrays? What if I alternately wanted to sort the files by name, size or date without re-reading the directory each time?
Would an associative array structure be better suited to this type of operation?
Thanks for your insight,
Javier
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com