PHP IF 语句帮助 - OR AND 等
我有一个小问题。我希望创建一个 IF 语句,其反应如下:
- 如果用户不是管理员 (forum_admin) 并且他们不是票证的所有者 (userid),但版主可以查看票证 (allow_moderator_tickets) 并且用户是版主 ( forum_moderator),那么他应该被允许查看票证。
我如何使用 PHP if 语句获得它。
到目前为止我有这个:
//If user is not allowed to view.
if($userdata['forum_admin']==0 && $ticketDetails['userid']!=$userdata['id'] || $sdata['allow_moderator_ticket']==0 && $userdata['forum_moderator']==1)
redirect("?i=a");
I have a little problem. I wish to create an IF statement, that shall react like this:
- If user is NOT admin (forum_admin) AND they are not the owner of the ticket (userid), BUT moderators are allowed to view tickets (allow_moderator_tickets) AND user is moderator (forum_moderator), then he should be allowed to view the ticket.
How can I obtain this with a PHP if statement.
So far I have this:
//If user is not allowed to view.
if($userdata['forum_admin']==0 && $ticketDetails['userid']!=$userdata['id'] || $sdata['allow_moderator_ticket']==0 && $userdata['forum_moderator']==1)
redirect("?i=a");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不能混合使用 and 和 or 运算符。彼此都会宠坏另一个。
您应该使用括号对表达式进行分组,就像算术一样,
重构您的代码以使其可读会很好
you cannot mix and and or operators. each other will spoil another.
you should group your expressions, using parenthesis, much like in arithmetics
it would be nice to refactor your code to make it readable