title: How to reorder a drop down list in PHP
body: <p>I have a database with index values stored in it.  The data corresponds to other named data, contained elsewhere in a flat file.</p>
  
  <p>I'm reading the data out of the database and matching the index value with the corresponding named data, but none of it is in any kind of order.  There's not a way for me to order the data being selected out of the database, in order to have the named data be listed in order in the drop down.</p>
  
  <p>Is there a way for me to order the list once I have everything matched up, before I display it to the user?  Here's the code I have that does the matching.</p>
  
  <pre><code>while ($y &lt;= $totalItemsAvail) #Loops based on the number of items needed.
  {
      $itemNumberRet = getItemNames($y);
      $itemOptions.="&lt;option value=\"$y\"&gt;".$itemNumberRet.'&lt;/option&gt;';
      $y++;
  }
  </code></pre>
  
  <p>I'd like to order the list here alphabetically before I actually display the options for the user.</p>
  
  <p>The data looks something like this, with the item number coming from the db, and the name from the flat file:</p>
  
  <pre><code>ID          Name
  1           Frank
  2           Andy
  3           Tom
  4           Charles
  5           Betty
  6           Ashley
  7           Ben
  </code></pre>
  
  <p>I'd like the list to display in alphabetical order, but also to retain the original index value stored in the <code>$y</code> variable.</p>