Last active
October 14, 2020 16:31
-
-
Save jfinstrom/7b6db173a40a9e4b037a2c652a3b6132 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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