Reputation: 22547
Is it possible to do something like this in a php if
statement:
if($a == '1' || ($b == '2' && $c == '3')) echo "foo walks into a bar";
(also, is the title of my question phrased correctly?)
Upvotes: 2
Views: 150
Reputation: 132021
Of course you can.
http://www.php.net/manual/en/language.operators.precedence.php
Upvotes: 4
Reputation: 4315
They absolutely can! I think it'd be called something like a "multiple condition if()" statement.
Upvotes: 0
Reputation:
Yes, as $a == '1' || ($b == '2' && $c == '3')
evaluates into a Boolean expression. Think of ||
and &&
as mathematical operators, and you can apply brackets to them to alter their order of operations.
Upvotes: 5
Reputation: 1020
Think you might need to bracket up the first condition:
if(($a == '1') || ($b == '2' && $c == '3')) echo "foo walks into a bar";
Upvotes: 0