Dropdown selct list


Hello everyone,
I use this code to create a select dropdown list of folders in a directory:

<select id="target"  name="event">
            foreach(glob(dirname(__FILE__) . '/digital_orders/*') as $filename){
            $filename = basename($filename);
            echo "<option value='" . $filename . "' selected='" . $filename . "'>".$filename."</option>";

I need to sort the values by date. I googled and find out somethingh like:

usort($filename, function($a,$b){return filemtime($a) - filemtime($b);});

I'm not able to work it out. Could anyone help me please?


I would think you'll need to separate the loop from the display. Pseudo-code:

create a blank array
foreach // as you have it
  append each file to an array as elelement ['name']
  add the filemtime() information to that array as ['ftime']
  end foreach
sort the array
loop through the sorted array to display

My guess on the sort would be more like

uasort($filearray, function($a, $b) {
  if ($a['ftime'] > $b['ftime']) return -1;
  if ($a['ftime'] < $b['ftime']) return 1;
  return 0;


Thank you. I 'm not sure I 'll be able to do what you suggest. I'll try


OK, if you run into problems come back and post the code, and people will try to help.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.