What are some common pitfalls when working with select elements with multiple options in PHP?

One common pitfall when working with select elements with multiple options in PHP is not properly handling the selected option when the form is submitted. To solve this issue, you need to check which option was selected and set it as the "selected" attribute in the HTML output.

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