What are the best practices for handling user input and decision-making processes within PHP scripts?

When handling user input and decision-making processes within PHP scripts, it is important to sanitize and validate user input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. Additionally, using conditional statements and loops can help make decisions based on user input and execute the appropriate actions.

// Example of handling user input and decision-making process
$userInput = $_POST['user_input'];

// Sanitize and validate user input
$sanitizedInput = filter_var($userInput, FILTER_SANITIZE_STRING);

// Decision-making process
if ($sanitizedInput == 'option1') {
    // Execute code for option 1
} elseif ($sanitizedInput == 'option2') {
    // Execute code for option 2
} else {
    // Handle invalid input
    echo 'Invalid input. Please try again.';
}