PHP Logical Operators

PHP Comparison Operators Previous Next PHP If Statement


PHP Logical operators is used to perform logical operations on the given expressions or combined logical expressions.

There are 6 logical operators in php given below.

#
Operator
Operator Name
Example
Description
1
and
Logical And
$a and $b
It is true if both condition are true
2
or
Logical OR
$a or $b
It is true if one of them condition is true
3
Xor
Logical Xor
$a xor $b
It is true if either $x or $y is true, but not both
4
&&
Logical And
$a && $b
It is true if both condition are true
5
||
Logical OR
$a || $b
It is true if one of them condition is true
6
!
Logical NOT
!$a
It is true if given condition is not true.

Logical and or logical && is same only difference is symbol.

Logical or or logical || is same only difference is symbol.

Filename: php / logical-and.php


Code
<?php
//LogicalAnd
$a = 10;
$b = 20;
if($a == 10 and $b == 20){
echo "Logical And Condition is True";
}
?>

Running Step.


Type URL - https://localhost/php/logical-and.php

Output
Logical And Condition is True

Filename: php / logical-or.php


Code
<?php
//LogicalOr
$a = 10;
$b = 20;
if($a == 10 or $b == 40){
echo "Logical Or One Condition is True";
}
?>

Running Step.


Type URL - https://localhost/php/logical-or.php

Output
Logical Or One Condition is True

Filename: php / logical-and1.php


Code
<?php
//Logical&&
$a = 10;
$b = 20;
if($a == 10 && $b == 20){
echo "Logical And Condition is True";
}
?>

Running Step.


Type URL - https://localhost/php/logical-and1.php

Output
Logical And Condition is True

Filename: php / logical-or1.php


Code
<?php
//LogicalOr1
$a = 862;
$b = 27;
if($a == 10 || $b == 40){
echo "Logical Or One Condition is True";
}
?>

Running Step.


Type URL - https://localhost/php/logical-or1.php

Output
Logical Or One Condition is True

Filename: php / logical-not.php


Code
<?php
//Logical
$a = 10;
if($a != 8){
echo "Logical Not Condition is true";
}
?>

Running Step.


Type URL - https://localhost/php/logical-not.php

Output
Logical Not Condition is true

Tags: PHP


Was this helpful ?

Related Code


Popular Code

Latest Code