Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

PHP: Create a SELECT input field

Creates a SELECT input field with an optional parameter to preselect an item

function selectfield($optionsarray, $selected = "") {
  $returnval = "";
  foreach ($optionsarray as $field=>$value) {
    if ($field == $selected) {
      $returnval .= "<option selected value='" . $field . "'>" . $value . "</option>\n";
    } else {
      $returnval .= "<option value='" . $field . "'>" . $value . "</option>\n";
    }
  }
  
  return $returnval;
}
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS