Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Logical disjunction (||)

One truthy operand suffices to produce true.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

$first || $second

One truthy operand suffices to produce true. A truthy left side skips the right expression, including its side effects. A second, more expensive check can therefore run only after the first one fails. The result is a boolean value.

$first || $second

[true,true,1]

Examples

<?php
$checks = 0;
$allowed = true || (++$checks > 0);
$retry = false || (++$checks > 0);
echo json_encode([$allowed,$retry,$checks]);

Result

[true,true,1]

Sources