Re: sorting results of opendir()

From: Date: Tue, 10 Jul 2001 05:27:11 +0000
Subject: Re: sorting results of opendir()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-57074@lists.php.net to get a copy of this message
On 09-Jul-01 Steve Edberg wrote: > Here's one way: > > > $dir = opendir('.'); > unset($FileList); > > while ($file=readdir($dir)) { > > if($file!= '.' && $file != '..') > { > $FileList[] = $file; > } > > } > > sort $FileList; > reset($FileList); > > while(list(, $F) = each($FileList)) { > > echo "$F<br>\n"; > > } > > If you're using PHP4, you can replace everything after the > sort($FileList) with the more compact: > > foreach($FileList as $F) { echo "$F<br>\n"; } > > > See > > http://www.php.net/manual/en/function.sort.php > > for more info on sorting arrays. > > > - steve > > > > At 1:05 PM -0500 7/9/01, kmurrah wrote: >>Greetings. >> >>I need to read the contents of a directory, sort it alphabetically, and >>display it .... >> >>i'm doing find on the reading and displaying, but can someone help me with >>the sort? >> >>$dir = opendir("."); >> >>while ($file=readdir($dir)) { >> >> >> if($file!= "." && $file != "..") >> { >> echo("$file<br>"); >> } >>} >> > > > -- > +------ Factoid: Of the 100 largest economies in the world, 51 are ------+ >| Steve Edberg University of California, Davis | >| sbedberg@ucdavis.edu Computer Consultant | >| http://aesric.ucdavis.edu/ >http://pgfsun.ucdavis.edu/ | > +--- corporations ------ > http://www.ips-dc.org/reports/top200text.htm ---+ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- Don Read dread@texas.net -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it.

« previous php.general (#57074) next »