When working with form elements in PHP, what is the correct syntax for setting the "selected" attribute in XHTML for dropdown options?

When working with form elements in PHP, to set the "selected" attribute in XHTML for dropdown options, you need to check if the current option's value matches the value that should be selected. If it matches, you add the "selected" attribute to that option. This ensures that the correct option is pre-selected when the form is rendered.

<select name="dropdown">
    <option value="option1" <?php echo ($selectedValue == 'option1') ? 'selected' : ''; ?>>Option 1</option>
    <option value="option2" <?php echo ($selectedValue == 'option2') ? 'selected' : ''; ?>>Option 2</option>
    <option value="option3" <?php echo ($selectedValue == 'option3') ? 'selected' : ''; ?>>Option 3</option>
</select>