PHP or Keyword

❮ PHP Keywords

Example

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

<?php
if (5 > 3 or 5 > 10) {
  echo "true";
} else {
  echo "false";
}
?>
Try it Yourself »

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";
?>
Try it Yourself »

❮ PHP Keywords
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.