php
  • operators
  • 2010-07-15 46 views 0 likes 
    0

    我想在php 5中使用和OR语句,但它只是不工作,这个脚本有什么问题。这是假设发射的错误,但它没有。如果我删除“||”(我认为是OR语句),它会引发错误。php 5 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"){ 
    

    回答

    1

    您的括号内容不正确。试试这个:

    ($fteamscore<$steamscore) && ($winner=="3" || $winner=="2") 
    

    没有任何括号,“and”首先被评估。你的表情相当于:

    (($fteamscore<$steamscore && $winner=="3") || $winner=="2") 
    

    更多关于运算符优先级:http://en.wikipedia.org/wiki/Logical_connective#Order_of_precedence

    +0

    您的回答最好。谢谢 – 2010-07-15 16:23:01

    2

    也许你需要parens?

    if($fteamscore<$steamscore && ($winner=="3" || $winner=="2")) { 
    

    这种方式是,在括号表达式正在& &“之前评估ð由于操作者的优先级。

    +0

    的回答总是那么简单再用。谢谢bro – 2010-07-15 15:40:21

    相关问题