PHP or Keyword

PHP Keywords : Return true if at least one of the statements is true

Definition and Usage

The or keyword is a logical operator.

Logical operators are used to combine conditional statements.

The return value will be true if any one of the statements returns true, otherwise it will return false.

The difference between or and || is that or has very low precedence, meaning that most other operations get evaluated first.

Related Pages

Read more about operators in our PHP Operators Tutorial.

More Examples

Example

Difference between or and ||. or has lower precedence than the = operator, so the assignment happens first.

<?php
$result1 = false || true;
echo "false || true = ";
echo $result1 ? "true" : "false";

echo "<br>";

$result2 = false or true;
echo "false or true = ";
echo $result2 ? "true" : "false";
?>

❮ PHP Keywords