What is the best practice for updating a select box with a default value selected in PHP?

When updating a select box with a default value selected in PHP, you can achieve this by looping through the options and setting the 'selected' attribute on the option that matches the default value. This can be done by comparing the current option value with the default value and adding the 'selected' attribute if they match.

<select name="example_select">
    <?php
    $options = array('Option 1', 'Option 2', 'Option 3');
    $default_value = 'Option 2';

    foreach ($options as $option) {
        if ($option == $default_value) {
            echo '<option value="' . $option . '" selected>' . $option . '</option>';
        } else {
            echo '<option value="' . $option . '">' . $option . '</option>';
        }
    }
    ?>
</select>