What is the difference between preselecting radio buttons and dropdown lists in PHP?

Preselecting radio buttons involves setting the 'checked' attribute on the desired radio button option, while preselecting dropdown lists involves setting the 'selected' attribute on the desired dropdown option. This can be done dynamically in PHP by checking the value of the option against a variable and adding the 'checked' or 'selected' attribute accordingly.

// Preselecting radio buttons
$selectedOption = 'option2'; // This value can be dynamic
$options = ['option1', 'option2', 'option3'];

foreach ($options as $option) {
    $checked = ($selectedOption == $option) ? 'checked' : '';
    echo "<input type='radio' name='radio_option' value='$option' $checked> $option <br>";
}

// Preselecting dropdown list
$selectedOption = 'option2'; // This value can be dynamic
$options = ['option1', 'option2', 'option3'];

echo "<select name='dropdown_option'>";
foreach ($options as $option) {
    $selected = ($selectedOption == $option) ? 'selected' : '';
    echo "<option value='$option' $selected>$option</option>";
}
echo "</select>";