Re: sorting array question

From: Date: Tue, 03 Sep 2002 13:39:29 +0000
Subject: Re: sorting array question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-115025@lists.php.net to get a copy of this message
There is readdir() to read a complete directory. It will put it into an array, then use asort to class it. -- Merci de nous avoir choisi. - Thanks you for your choice. Nicos - CHAILLAN Nicolas nicos@worldakt.com nicos@php.net www.GroupAKT.com - Hébergement Group. www.WorldAKT.com - Hébergement de sites Internet "Javier Montserat" <codareef@hotmail.com> a écrit dans le message de news: F217XqxsD1Ty9CMdZpD00003ffd@hotmail.com... > 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 >

« previous php.general (#115025) next »