I am wondering how to sort select options alphabetically. I was reading on another page where you can jQuery and I completely get the hang of it, I'm just confused a tad bit how I'd use it on the code I use for my selecting.
Here's my selection code:
<select class="form-control" id="rareImage" name="rareImage">
<?php
if($open = opendir(ROOT .'/resources/images/small_furni')) {
while(false != ($file = readdir($open))) {
if($file == '.' || $file == '..') {
continue;
}
echo '<option value="'. $file .'" '. ((isset($rareimage) && $rareimage == $file) ? 'selected' : '') .'>'. $file .'</option>';
}
}
?>
</select>
The other page suggested giving it a option value and then using jQuery to sort it. But like I said, I'm kind of confused how I'd go about using it on this code. Basically, the above code outputs a list of images to select from, but they're not in alphabetical order.
Reference I used: http://jsfiddle.net/3YjNR/2/