What are the best practices for maintaining the selected dropdown value after a page reload in PHP?

When a user selects a value from a dropdown menu on a form and submits the form, the selected value is lost when the page reloads. To maintain the selected dropdown value after a page reload in PHP, you can use the $_POST superglobal array to check if the form has been submitted and then set the "selected" attribute in the dropdown options based on the submitted value.

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