Skip to content

Instantly share code, notes, and snippets.

@jfinstrom
Last active October 14, 2020 16:31
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 jfinstrom/7b6db173a40a9e4b037a2c652a3b6132 to your computer and use it in GitHub Desktop.
Save jfinstrom/7b6db173a40a9e4b037a2c652a3b6132 to your computer and use it in GitHub Desktop.
<?php
$options = include(__DIR__.'/options.php');
?>
<html lang="en">
<head>
<title>Select PHP Example</title>
</head>
<body>
<select id="example" name="example">
<?php echo $options ?>
</select>
</body>
</html>
<?php
$data = [
'foo' => 'bar',
'bar' => 'baz',
];
$selection = 'bar';
$output = '';
foreach($data as $value => $label)
{
$selected = $value === $selection ? 'SELECTED' : '';
$output .= sprintf('<option = "%s" %s>%s</option>', $value, $selected, $label);
}
return $output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment