What are the different logical operators used in PHP and how do they work?

In PHP, there are three main logical operators: AND (&&), OR (||), and NOT (!). These operators are used to combine multiple conditions in a logical expression. The AND operator returns true if both conditions are true, the OR operator returns true if at least one condition is true, and the NOT operator returns the opposite of the condition.

// Example of using logical operators in PHP
$age = 25;
$gender = 'female';

if ($age >= 18 && $gender == 'female') {
    echo "You are a female adult.";
} elseif ($age < 18 || $gender == 'male') {
    echo "You are either a male or not an adult.";
} else {
    echo "You do not fit the criteria.";
}