我正在尝试在php 5中使用和OR语句,但它只是不起作用,这个脚本有什么问题。它假设发出错误,但事实并非如此。如果我删除“||”(我认为是OR语句)它会触发错误。
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"){
答案 0 :(得分:2)
也许你需要parens?
if( $fteamscore<$steamscore && ($winner=="3" || $winner=="2" ) ) {
这样,由于运算符优先级,在&amp;&amp; d之前评估parens中的表达式。
答案 1 :(得分:1)
你的括号错了。试试这个:
($fteamscore<$steamscore) && ($winner=="3" || $winner=="2")
没有任何括号,首先评估“和”。你的表达相当于:
(($fteamscore<$steamscore && $winner=="3") || $winner=="2")
有关运算符优先级的更多信息:http://en.wikipedia.org/wiki/Logical_connective#Order_of_precedence