Skip to content

Instantly share code, notes, and snippets.

@danielrw7
Created August 1, 2016 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielrw7/07edcd4850add4f0366188d6dc7d098b to your computer and use it in GitHub Desktop.
Save danielrw7/07edcd4850add4f0366188d6dc7d098b to your computer and use it in GitHub Desktop.
<?php
function make_select($name, $options, $selected = "", $additional_attrs = "") {
$res = "<select";
if ($name) {
$res .= " name='$name'";
}
if ($additional_attrs) {
$res .= " $additional_attrs";
}
$res .= ">";
foreach ($options as $value => $label) {
$res .= "<option value='$value'";
if ($selected == $value) {
$res .= " selected";
}
$res .= ">$label";
$res .= "</option>";
}
$res .= "</select>";
return $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment