Order the options of a select list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tdrsam
    New Member
    • May 2015
    • 97

    Order the options of a select list

    I have a php for loop that generates a select list, but I can't figure out how to order the options of the list the way I want.

    This is the php:

    Code:
    static function tp_widget_do($args) {
      echo '<span class="' . NO_TRANSLATE_CLASS . '">';
    
      echo '<select name="lang" onchange="document.location.href=this.options[this.selectedIndex].value;">'; 
    
      foreach ($args as $langrecord) {
        $is_selected = $langrecord['active'] ? " selected=\"selected\"" : "";
        echo "<option value=\"{$langrecord['url']}\"{$is_selected}>{$langrecord['langorig']}</option>";
      }
      echo "</select><br/>";
    
      echo "</span>";
    }
    I was thinking of using either 'usort' or maybe even some javascript to sort the list of options in the select list. What I really need is to sort them in descending order.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    that's correct. you would use usort() for that.

    Comment

    Working...