Is this the correct way to do two equal statements in one?
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_BOO开发者_Go百科LEAN_AND
You need to do:
if (( $1 === $one ) && ( $2 == $two )) {
Or:
if ( $1 === $one && $2 == $two ) {
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.
x || y
x && y
x && (y || z)
x || (y && z)
Should be:
if (( $1 === $one ) && ( $2 == $two )) {
require("one.php");
} elseIF($2 === $two) {
require("two.php");
} else {
require("three.php");
die("");
}
You need to wrap the two conditions in your first IF statement in additional brackets:
if (( $1 === $one ) && ( $2 == $two ))
if (( $1 === $one ) && ( $2 == $two )) {
require "one.php";
} elseif ($2 === $two) {
require "two.php";
} else {
require "three.php";
die("Some message");
}
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.
精彩评论