How can the number of options in a dropdown be dynamically set based on a variable in PHP?

To dynamically set the number of options in a dropdown based on a variable in PHP, you can use a loop to generate the options based on the variable value. You can iterate over the variable value and create option elements with corresponding values.

<select>
<?php
$variable = 5; // Variable with the number of options
for ($i = 1; $i <= $variable; $i++) {
    echo "<option value='$i'>$i</option>";
}
?>
</select>