What best practices should be followed when generating HTML code using PHP, specifically in relation to radio buttons?

When generating HTML code using PHP for radio buttons, it is important to ensure that each radio button has a unique "name" attribute but the same "value" attribute within a group. This allows only one option to be selected at a time within the group. Additionally, each radio button should have a corresponding label for better accessibility and usability.

<?php
$radioOptions = array("option1", "option2", "option3");

foreach($radioOptions as $option) {
    echo '<input type="radio" id="' . $option . '" name="radioGroup" value="' . $option . '">';
    echo '<label for="' . $option . '">' . $option . '</label><br>';
}
?>