How can dynamic values be assigned to each option in a dropdown list generated using PHP?
To assign dynamic values to each option in a dropdown list generated using PHP, you can create an array with the values you want to assign and then loop through the array to generate the options with the corresponding values.
<select name="dropdown">
<?php
$options = array(
'Option 1' => 'value1',
'Option 2' => 'value2',
'Option 3' => 'value3'
);
foreach ($options as $option => $value) {
echo "<option value='$value'>$option</option>";
}
?>
</select>
Keywords
Related Questions
- Are there any specific PHP libraries or tools recommended for working with Exchange Online Calendar?
- In the context of the provided PHP code, what are the key differences between using $_POST and $HTTP_POST_VARS for form data retrieval?
- What is the purpose of using the PHP Captcha validation in the provided code snippet?