Are there best practices for handling user selection in PHP dropdown menus to display relevant options?

When handling user selection in PHP dropdown menus to display relevant options, it is important to use conditional statements to determine which options should be shown based on the user's selection. This can be achieved by using if-else or switch statements to dynamically populate the dropdown menu with the appropriate options.

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