多条件IF语句 [英] Multiple condition IF statement

查看:89
本文介绍了多条件IF语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个if语句有多个条件我似乎无法正确

I've got an if statement with multiple conditions that I just can't seem to get right

if(((ISSET($_SESSION['status'])) && ($_SESSION['username']=="qqqqq")) ||     
((ISSET($_SESSION['status'])) && ($_SESSION['company']=="wwwwww")) || 
((ISSET($_SESSION['status'])) && ($_SESSION['company']=="ffffffff")) || 
((ISSET($_SESSION['status'])) && ($_SESSION['company']=="ggggggg")) || 
((ISSET($_SESSION['status'])) && ($_SESSION['company']=="hhhhhhh")) || 
($_SESSION['LOGINTYPE']=="ADMIN")) {

如果状态设置为以及其中任何一个,它应该返回true那些公司名称OTHERWISE如果logintype是admin,它也应该返回true,无论公司或状态如何

Its supposed to return true if the status is set as well as either one of those company names OTHERWISE if the logintype is admin it should also return true regardless of company or status

推荐答案

这个怎么样:

if (
  (isset($_SESSION['status']) && $_SESSION['username']=="qqqqq")
  || (isset($_SESSION['status']) && in_array($_SESSION['company'], array('wwwwww', 'ffffffff', 'ggggggg', 'hhhhhhh')))
  || $_SESSION['LOGINTYPE']=="ADMIN"
)

将条件重写为试着让它更容易阅读可能会有所帮助:

Rewriting the condition to try to make it a bit more easier to read might help :


  • 每行一个可能的情况:

    • 状态设置和用户名确定

    • 状态设置和公司确定

    • admin

    这篇关于多条件IF语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆