Reputation: 227
I'm trying to use and OR statement in php 5 but it's just not working, what's wrong with this script. It's suppose to fire the error but it doesn't. If I remove the "||"(what I thought was the OR statement) it fires the error.
if($winner=="2" && $fteamscore>$steamscore){
$return['error'] = true;
$return['msg'] = 'Wrong Score, You said you LOST but you are reporting that you WON.';
}
if($winner=="3" && $fteamscore>$steamscore){
$return['error'] = true;
$return['msg'] = 'Wrong Score, You said you WON but your are reporting that your OPPONENT won.';
}
if($fteamscore<$steamscore && $winner=="3" || $winner=="2"){
Upvotes: 0
Views: 90
Reputation: 27496
Your brackets are wrong. Try this:
($fteamscore<$steamscore) && ($winner=="3" || $winner=="2")
Without any brackets, the "and" is evaluated first. Your expression is equivalent to:
(($fteamscore<$steamscore && $winner=="3") || $winner=="2")
More on operator precedence: http://en.wikipedia.org/wiki/Logical_connective#Order_of_precedence
Upvotes: 1
Reputation: 186562
Perhaps you need parens?
if( $fteamscore<$steamscore && ($winner=="3" || $winner=="2" ) ) {
This way that expression in parens is evaluated before being &&'d due to operator precedence.
Upvotes: 2