Re: sorting results of opendir()

From: Date: Mon, 09 Jul 2001 18:42:28 +0000
Subject: Re: sorting results of opendir()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-56995@lists.php.net to get a copy of this message
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 ---+

« previous php.general (#56995) next »