Monday 25 October 2021

PHP or syntax function

 https://stackoverflow.com/questions/9535255/php-or-syntax



Let's just say that:

$result = first() || second();

will evaluate to:

if (first()) {
    $result = true;
} elseif (second()) {
    $result = true;
} else {
    $result = false;
} 

while:

$result = first() or second();

will evaluate to:

if ($result = first()) {
    // nothing
} else {
    second();
}

In other words you may consider:

$result = first() || second();

$result = (first() || second());

and:

$result = first() or second();

to be:

($result = first()) || second();

It is just matter of precedence.

No comments:

Post a Comment