What are some best practices for organizing and structuring PHP code within a dropdown menu?

When organizing and structuring PHP code within a dropdown menu, it is best practice to separate the HTML markup from the PHP logic. This can be achieved by using PHP to dynamically generate the dropdown options based on data retrieved from a database or an array. By keeping the PHP logic separate from the HTML markup, it makes the code easier to maintain and modify in the future.

<select name="dropdown">
<?php
// Example array of dropdown options
$options = array("Option 1", "Option 2", "Option 3");

// Loop through the options array to generate dropdown options
foreach ($options as $option) {
    echo "<option value='$option'>$option</option>";
}
?>
</select>