What best practice should be followed when building a select option in PHP to handle post submissions effectively?

When building a select option in PHP to handle post submissions effectively, it is important to ensure that the selected option is retained and displayed correctly after the form submission. This can be achieved by setting the 'selected' attribute for the option that matches the submitted value. Additionally, make sure to sanitize and validate the submitted data to prevent any security vulnerabilities.

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