What are some best practices for simplifying and optimizing if statements in PHP for form validation?

When performing form validation in PHP, it's important to simplify and optimize your if statements to make your code more readable and maintainable. One way to achieve this is by using ternary operators and logical operators to combine conditions. This helps reduce the number of nested if statements and makes the code more concise.

// Example of simplifying if statements for form validation
$name = $_POST['name'] ?? '';
$email = $_POST['email'] ?? '';

// Check if name and email are not empty
if (!empty($name) && !empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Form validation successful
    echo 'Form submitted successfully!';
} else {
    // Form validation failed
    echo 'Please enter a valid name and email address.';
}