What potential pitfalls should be considered when using the selected attribute in HTML dropdown options with PHP?

When using the selected attribute in HTML dropdown options with PHP, it is important to consider that the selected attribute should only be applied to one option at a time. If multiple options have the selected attribute, it may lead to unexpected behavior in the dropdown menu. To avoid this pitfall, make sure to dynamically set the selected attribute based on the value retrieved from PHP.

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