How can radio buttons be excluded from refreshing in PHP?

When a form is submitted in PHP and the page refreshes, radio buttons can lose their selected state. To prevent this, you can use PHP to check if a radio button is selected and set it accordingly after the form submission.

<input type="radio" name="option" value="1" <?php if(isset($_POST['option']) && $_POST['option'] == '1') echo 'checked'; ?>> Option 1
<input type="radio" name="option" value="2" <?php if(isset($_POST['option']) && $_POST['option'] == '2') echo 'checked'; ?>> Option 2
<input type="radio" name="option" value="3" <?php if(isset($_POST['option']) && $_POST['option'] == '3') echo 'checked'; ?>> Option 3