How can a PHP if statement be used to handle form field selections?

When handling form field selections in PHP, you can use an if statement to check if a specific option has been selected by the user. This can be useful for validating user input or executing certain actions based on the selected option. To implement this, you can use the $_POST superglobal array to access the value of the selected option and then use an if statement to perform the necessary logic.

if(isset($_POST['field_name'])) {
    $selected_option = $_POST['field_name'];

    if($selected_option == 'option1') {
        // Perform actions for option1
    } elseif($selected_option == 'option2') {
        // Perform actions for option2
    } else {
        // Handle other options
    }
}