What best practices should be followed when handling user input in PHP to ensure proper variable assignment and conditional statement evaluation?

When handling user input in PHP, it is important to properly sanitize and validate the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. Additionally, it is crucial to assign user input to variables using appropriate data types and to evaluate conditional statements securely to avoid unexpected behavior.

// Example of handling user input in PHP
$user_input = $_POST['user_input'] ?? ''; // Sanitize user input
$user_input = filter_var($user_input, FILTER_SANITIZE_STRING); // Validate user input

// Assign user input to a variable with appropriate data type
$number = (int) $_POST['number'] ?? 0; // Cast to integer for numeric input

// Securely evaluate conditional statements
if ($number > 10) {
    echo "Number is greater than 10";
} else {
    echo "Number is less than or equal to 10";
}