Jump to content

Recommended Posts

Alright, I've got this drop down working where it pulls all the files in. Is there a way to sort them alphabetically?
Here's the code. Thanks for the assist.

[code]
><select name='filename' id='filename'>
<?php
if ($handle = opendir('/path/to/the/options_sheets')) {
  /* This is the correct way to loop over the directory. */
  while (false !== ($file = readdir($handle))) {
  if ($file != "." && $file != "..") {
      echo "<option value='$file\n'>$file\n</option>";
  }
  }
  closedir($handle);
}
?>
</select>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/34623-sorting-directory-list-in-dropdown/
Share on other sites

just to let you know,
$files[] = $filename
this has to be used within a loop...(above)
and there are a lot of different sorts, the basic ones are
sort()
sorts alphebitcally
and
rsort()
oppisite sort()
but these two are case sensitive, for none case sensitive sorts, natcasort() would be a better choice...
Ted
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.