What is the best practice for preselecting a radio button in PHP without requiring user interaction?

When preselecting a radio button in PHP without requiring user interaction, you can achieve this by setting the "checked" attribute for the desired radio button option. This can be done by checking a condition and outputting the "checked" attribute accordingly in the HTML output.

<?php
// Assume $selectedOption contains the value of the option to be preselected

// Radio button options
$options = array('Option 1', 'Option 2', 'Option 3');

// Loop through options and output radio buttons
foreach ($options as $option) {
    // Check if the current option is the selected one
    $checked = ($option == $selectedOption) ? 'checked' : '';

    // Output radio button with the "checked" attribute if selected
    echo '<input type="radio" name="option" value="' . $option . '" ' . $checked . '>' . $option . '<br>';
}
?>