dongyan1936 2014-10-16 08:49
浏览 52
已采纳

if语句中的布尔条件

I want to double check something about multiple conditions in a boolean if statement in PHP. Given that I write:

if(!empty($_POST) && !isset($_POST['report_btn'])) {...}

can this be re-written as

if(! ( empty($_POST) && isset($_POST['report_btn']) ) ) {...}

I'm wanting to remove one of the exclamation marks to see if I can make the code a bit tidier. The logic is to see if I can execute the code if POST data has been sent to a page but the 'report_btn' value is not set.

  • 写回答

3条回答 默认 最新

  • drmeu26880 2014-10-16 08:59
    关注

    No, You can not write the above condition as below condition:

    Reason:

    for:

    if(! ( empty($_POST) && isset($_POST['report_btn']) ) ) {...}
    

    the result matrix will:

    first_statement second_statement result
       true            true          false
       true            false         true
       false           true          true
       false           false         true
    

    And for the below

    if(!empty($_POST) && !isset($_POST['report_btn'])) {...}
    

    The result matrix will be:

    first_statement second_statement result
       true            true          false
       true            false         false
       false           true          false
       false           false         true
    

    It means both code are not similar.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python怎么在已有视频文件后添加新帧
  • ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
  • ¥15 fluent里模拟降膜反应的UDF编写
  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵