PHP All Logical Operators Example Tutorial

Use logical operator and, or, xor, not inside php program to combine two or multiple conditional statements.

There are six types of conditional operators currently present in php programming language which is used to combine two or multiple conditional statements so developer can execute its own line of work with executing multiple conditions at once. So here is the complete step by step tutorial for PHP All Logical Operators Example Tutorial.

android-project-download-code-button

PHP All Logical Operators Example Tutorial.

Operator NameOperator Symbol Example with $a and $bFinal Output Result
Andand$a and $bReturns True if $a and $b both variables are true.
And&&$a && $bReturns True if $a and $b both variables are true.
Oror$a or $bReturns True if $a and $b or any of them variables are true.
Or||$a || $bReturns True if $a and $b or any of them variables are true.
Xorxor$a xor $bReturn True if either only $a or only $b is true.
Not!$a ! $bReturns True if $a is not true.

Code for Logical-Operators-program.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP Logical Operators example tutorial</title>
</head>

<body>

<?php
$a = 10;

$b = 12;

if( $a == 10 and $b == 12)
{
 echo " And operator called.".'</br>'; 
}


if( $a == 10 && $b == 12)
{
 echo " And operator called. ".'</br>'; 
}


if( $a == 10 or $b == 12)
{
 echo " Or operator called. ".'</br>'; 
}


if( $a == 10 || $b == 12)
{
 echo " Or operator called. ".'</br>'; 
}


if( $a == 10 xor $b == 12)
{
 echo " Xor operator called. ".'</br>'; 
}


if( $a !== 12 )
{
 echo " Not operator called. ".'</br>'; 
}



?>
</body>
</html>

Screenshot :

PHP All Logical Operators Example Tutorial

Click here to download PHP All Logical Operators Example Tutorial project file.