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.
PHP All Logical Operators Example Tutorial.
Operator Name | Operator Symbol | Example with $a and $b | Final Output Result |
---|---|---|---|
And | and | $a and $b | Returns True if $a and $b both variables are true. |
And | && | $a && $b | Returns True if $a and $b both variables are true. |
Or | or | $a or $b | Returns True if $a and $b or any of them variables are true. |
Or | || | $a || $b | Returns True if $a and $b or any of them variables are true. |
Xor | xor | $a xor $b | Return True if either only $a or only $b is true. |
Not | ! | $a ! $b | Returns 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 :