php Logical operators

php scripts anvar in

Logical operators first convert their operands to Boolean (True or false) values and then perform the respective comparison. The standard logical operators and, or, not, and xor are supported by PHP.

Here is the list of logical operators :

Operator Name Example Result
&& and $x && $y is true if both $x and $y are true.
|| or $x || $y is true if either $x or $y is true.
xor xor $x xor $y is true if either $x or $y are true, but not both.
! not !$x is true if $x is not true.
and and $x and $y is true if both $x and $y are true.
or or $x or $y is true if either $x or $y is true.

The real time example The && symbols mean AND.

Use this if you need both values to be true, as in our username and password test. After all, you don’t want to let people in if they just get the username right but not the password! Here’s an example:

$username ='user';
$password ='password';
if ($username =='user' && $password =='password') {
print("Welcome back!");
}
else {
print("Invalid Login Detected");
}