Over a million developers have joined DZone.

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 .= "\n";
    } else {
      $returnval .= "\n";
    }
  }
  
  return $returnval;
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}