Forum Moderators: coopster

Message Too Old, No Replies

Sort alphabetically

Sorting an array

         

ahmedtheking

3:50 pm on Aug 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How can i sort this alphabetically?

$dir = "dir/"; 
// Open a known directory, and proceed to read its contents
if ($dh = opendir($dir)) { // open the dir
while (($file = readdir($dh))!= false) { // read the files
$ext = explode('.',$file);
if($file!= '.' && $file!= '..' && $ext[ 1 ]=='php') {
$filearray = explode('.',$file);
$filename = reset($filearray);
$getcat = urlencode($filename);
echo "<li><a href=\"/dirindex.php?cat=$getcat\">$filename</a></li>\n";
}
}
closedir($dh);
}

[edited by: jatar_k at 4:25 pm (utc) on Aug. 14, 2004]
[edit reason] reformatted for easier reading [/edit]

jatar_k

4:26 pm on Aug 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, the only way I can think of is to read all the info into an array instead of echoing it. Then sort the array and use a foreach to build and output the links.

coopster

12:23 am on Aug 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Some related threads...

[webmasterworld.com...]
[webmasterworld.com...]