What is the best practice for comparing parameters and values in radio buttons using PHP?

When comparing parameters and values in radio buttons using PHP, it's important to ensure that the values are properly sanitized and validated to prevent any security vulnerabilities. One common approach is to use an if statement to check if the parameter value matches the expected value of the radio button.

// Assuming 'radio_button' is the name of the radio button input field
$selected_value = $_POST['radio_button'];

if ($selected_value == 'option1') {
    // Perform actions for option 1
} elseif ($selected_value == 'option2') {
    // Perform actions for option 2
} else {
    // Handle any other cases or errors
}