Skip to content

PHP Logical Operators

Syntax

Logical operators in PHP are used to combine multiple conditions or expressions. The result is a boolean value (true or false).

<?php
// AND operators
&& // true if both conditions are true
and // true if both conditions are true
// OR operators
|| // true if at least one condition is true
or // true if at least one condition is true
// NOT operator
! // true if the condition is false
?>

Example

<?php
$isAdult = true;
$hasPermission = false;
echo($isAdult && $hasPermission); // Outputs:
echo($isAdult || $hasPermission); // Outputs: 1
echo(!$isAdult); // Outputs:
?>