unknown os platform
Free Beginner PHP Tutorials - Logical operators | Whats-online.info
whats-online-info

Free Beginner PHP Tutorials - Logical operators


Free
2016:09:14 / Science and Tutorials

PHP Logical Operators are used to connect conditional statements. See example:-





PHP Logical Operators


PHP Logical Operators are used to connect conditional statements.

The PHP logical operators include:

1. and
2. or
3. xor
4. &&
5. ||
6. !

For this article, we will discuss each logical operator and give an application for each.

logical 'AND' operator

Tests True if both operands are true.

Example

<?php $x=20; $y=30; if($x==20 AND $y==30){   echo"Both expressions  are true"; } ?>

Results: Both expressions are true.

logical 'Or' operator

Tests True if either operand is true.

Example

<?php $x=30; $y=30; if($x==20 Or $y==30){   echo"One of the expression  is true"; } ?>

Results: One of the expression  is true.

logical 'Xor' operator

Tests True if either operand is true but not both.

Example

<?php $x=30; $y=30; if($x==20 Xor $y==30){   echo"One of the expression  is true, but not both"; } ?>


Results: One of the expression is true, but not both.

logical '&&' operator

Tests True if both operands are true.
Is used the same way as 'logical And Operator.'

Example

<?php $x=30; $y=30; if($x==30 && $y==30){   echo "Both expressions are true"; } ?>

Results: Both expressions are true.

logical '!' operator

Tests True if the operand is not true.

Example

<?php $x=100; if($x != 20){   echo"$x is true"; } ?>

Results: $x is true











You may also like:


Leave a comment












Subscribe to get replies direct to your mailbox

Submit comment