PHP 如果这个或者那个或者那个,怎么样?
我需要帮助弄清楚如何使这个 IF 发挥作用。它基本上检查第一个条件是否和(第二个或第三个条件)中的一个为真。
IF ( ($a=1) && ($b=2 || $c=3) ) {
echo "match found";
};
I need help figuring out how to make this IF work. It basically checks IF first condition AND either of (second or third condition) are true.
IF ( ($a=1) && ($b=2 || $c=3) ) {
echo "match found";
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当试图查看 IF a、b 和 c 分别等于 1,2 和 3 时,您应该有两个等号(比较运算符)。
另外,为了使用正确的语法,最好用小写字母编写 IF 并删除 if 语句末尾的分号。
You should have double equal(comparison operator) signs when trying to see IF a,b and c are equal to 1,2 and 3 respectfully.
Also, in order to use proper syntax it would be better to write the IF in lowercase letters and remove the semicolon at the end of the if statement.
您使用的是赋值运算符 (
=
),而不是比较运算符 (==
)。以下是一些有关运算符的 PHP 文档的链接: http://php.net/manual/ en/language.operators.php
You were using assignment operators (
=
) rather than comparison operators (==
).Here is a link to some PHP documentation about operators: http://php.net/manual/en/language.operators.php
为什么我要这样写?
在根据值检查变量时,将值放在前面:
=
而不是==
或===
更新: 要了解 < code>== 和
===
运算符,前往 php == 与 === 运算符Why have I written it this way around?
When checking vars against values, putting the value first:
=
instead of==
or===
Update: To read about the difference between the
==
and===
operators, head over to php == vs === operator您需要使用正确的运算符。当前您将所有变量分别设置为 1、2、3。这会导致每个语句的计算结果始终为 true。
正确的比较运算符是
==
You need to use the proper operator. Currently you are setting all your variables equal to 1, 2, 3 respectively. This causes each statement to always evaluate to true.
The correct comparisson operator is
==
好吧,我看到的问题是你在 IF 语句中分配变量
可能会更好
Well the issue i can see is you are assigning variables in your IF statement
Might work better