Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

PHP: Create A SELECT Input Field

DZone's Guide to

PHP: Create A SELECT Input Field

·
Free Resource
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:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}