Re: Sorting files in a directory

From: Date: Wed, 08 Aug 2007 22:07:00 +0000
Subject: Re: Sorting files in a directory
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-260458@lists.php.net to get a copy of this message
Steve Marquez wrote:
Greetings, I have some code that opens a directory and displays the files. I want to display the files in Alphabetical order. I know this code does not work, but I was curious if someone can take a look and tell me what is wrong? Thank you so much.
[ I hope the indenting is because you're posting to the list - tabs/spaces make it a lot easier to follow what's going on ] You have this: $file_array = array($file); sort ($file_array); foreach($file_array as $key => $value) {
    echo "<option value=\"$value\">".$value."</option>";
} You're "sorting" one element of an array and then printing it out. Not what you want. Try this cut down version: http://pastebin.com/m5bcadd77 Also note that in your example, if a directory can't be opened for whatever reason, then you don't get a select box at all - is that what you want to do? -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#260458) next »