Are there more efficient or elegant ways to handle selected values in a dropdown menu using PHP?

When handling selected values in a dropdown menu using PHP, one efficient and elegant way is to use a loop to iterate through the options and check if the current option matches the selected value. If it does, add the 'selected' attribute to that option. This approach reduces redundancy and makes the code more maintainable.

<select name="dropdown">
    <?php
    $options = ['Option 1', 'Option 2', 'Option 3'];
    $selectedValue = 'Option 2'; // Selected value

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