这是将两个相等的语句合而为一的正确方法吗?
我正在做同样的声明,但它不起作用。
if ( $1 === $one ) && ( $2 == $two ) {
require("one.php");
} elseIF($2 === $two) {
require("two.php");
}else{
require("three.php");
die("");
}
这是我收到的错误消息:
PHP Parse error: syntax error, unexpected T_BOOLEAN_AND
I am doing this equal statement and it's not working.
if ( $1 === $one ) && ( $2 == $two ) {
require("one.php");
} elseIF($2 === $two) {
require("two.php");
}else{
require("three.php");
die("");
}
And this is the error message i get:
PHP Parse error: syntax error, unexpected T_BOOLEAN_AND
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要执行以下操作:
或者:
请记住将其视为放置方括号的代数,需要将 'IF@ 语句作为一个整体进行评估,并将您希望评估的所有标准包含在 ( 和 ) 中。根据您希望进行评估的复杂程度(以公式化方式构建),您可以将后续标准括在括号中,例如
You need to do:
Or:
Remember to think of it as algebra in where you put brackets, the 'IF@ statement needs to be evaluated as a whole with all criteria you wish to evaluate being wrapped within ( and ). Depending on how complex you wish to make your evaluations (build it formulaically) you can then wrap subsequent criteria in brackets, e.g.
应该是:
Should be:
您需要将第一个 IF 语句中的两个条件括在附加括号中:
You need to wrap the two conditions in your first IF statement in additional brackets:
不,问题出在第一行。
do:
if ($1 === $one && $2 == $two) { ...
“if”条件始终位于单个“()”内。您可以嵌套它们,但 if 条件在第一个条件关闭后停止。所以
if (($1 === $one) && ($2 == $two))
也是有效的,但在这种情况下,不需要嵌套它,除非你发现它提高可读性。一些批评:
这些变量名非常糟糕,因为它们没有解释发生的事情。与文件名相同。
请在上面加上糖,修复你的缩进(查看 draevor 的答案以获得合适的缩进)。立即习惯正确的缩进,因为以后习惯改变的做法只会变得更加困难。当其他人开始使用你的代码时,如果你继续这样缩进,他们会诅咒你的名字。这对于可读性确实很重要。
No, the problem is in the first line.
do:
if ($1 === $one && $2 == $two) { ...
The "if" condition is always within a single "()". You can nest them, but the if-condition stops after the first one is closed. So
if (($1 === $one) && ($2 == $two))
is valid as well, but in this case there's no need for nesting it unless you find that it improves readability.A bit of criticism to the side:
Those variable names are very bad, since they don't explain anything about what's going on. Same with the file names.
And pretty please, with sugar on top, fix your indenting (check out draevor's answer for decent indenting). Get used to proper indenting right away, since it will only get more difficult to get used to a changed practice later. When someone else starts to work with your code, they'll curse your name if you keep indenting like that. It really does matter for readability.