What are the common mistakes made when setting radio button values in PHP?

When setting radio button values in PHP, a common mistake is not properly checking the selected value. To ensure that the correct radio button is selected based on a specific value, you need to compare the current value with the desired value and add the 'checked' attribute to the corresponding radio button.

// Example of setting radio button values in PHP
$selectedValue = "option2"; // Value that should be selected

// Radio button options
$options = array("option1", "option2", "option3");

// Loop through options and create radio buttons
foreach($options as $option) {
    echo '<input type="radio" name="radio_option" value="' . $option . '"';
    if($option == $selectedValue) {
        echo ' checked';
    }
    echo '>' . $option . '<br>';
}