Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP if statement: use "OR" or ||? [duplicate]

Possible Duplicate:
PHP - and / or keywords

if($foo == 0 or $bar == 1 || $baz == 2)
{
    ...
}

Is it better to use "or" or || and is there any significant difference between them?

like image 475
reformed Avatar asked Feb 28 '26 11:02

reformed


1 Answers

It's basically a matter of choice.

There is a difference however, when it comes to operand precedence:

if ( false && false || true ) // true

if ( false AND false || true ) // false

See it here in action: http://codepad.viper-7.com/zvFPzR

like image 141
Joseph Silber Avatar answered Mar 02 '26 00:03

Joseph Silber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!