Logical AND in PHP
The logical AND allows you to specify the simultaneity
of conditions. In the following example, the condition will be met
if the variable $num is greater than zero and
simultaneously less than 10:
<?php
$num = 3;
if ($num > 0 and $num < 10) {
echo '+++';
} else {
echo '---';
}
?>
Conditions can be imposed not on one variable,
but on different ones. In the following example, the condition
will be met if the variable $num1
is equal to 2 and simultaneously the variable
$num2 is equal to 3:
<?php
$num1 = 2;
$num2 = 3;
if ($num1 == 2 and $num2 == 3) {
echo '+++';
} else {
echo '---';
}
?>
Check that the variable $num
is greater than zero and less than 5.
Check that the variable $num
is greater than or equal to 10 and less than or equal to
20.
Check that the variable $num1
is equal to or less than 1, and the variable $num2
is greater than or equal to 3.