In PHP, is the following logic allowed
If (x && y)
//Do A
Elseif (x)
// Do B
Elseif (y)
// Do C
Else
// Do D
Basically, are you allowed to use more than one elseif?
In PHP, is the following logic allowed
If (x && y)
//Do A
Elseif (x)
// Do B
Elseif (y)
// Do C
Else
// Do D
Basically, are you allowed to use more than one elseif?
yup
if(this == this && this == this){
//this and that
}else if(this == that || this == that){
//this or that
}else{
//anything else
}
Yes:
if ($x && $y) {
//Do A
} else if ($x) {
// Do B
} else if ($y) {
// Do C
} else {
// Do D
}
Another format useful for HTML files
<?php if ($x && $y): ?>
Element A
<?php elseif ($x): ?>
Element B
<?php elseif ($y): ?>
Element C
<?php else: ?>
Element D
<?php endif;?>
Yes, although if the test is simple ($a == $b
), use a switch instead:
switch ($a) {
case $b:
break;
case $c:
break;
default:
//Like else
}
Yes. Please see http://us3.php.net/elseif and http://us3.php.net/elseif.
You can use
if($x)
// for one line of code
elseif($y)
// also for one line of code
if($x) {
// for more than
// one line of code
} elseif($y) {
// also for multi-
// line codes
}
and
if($x):
// multi-line
endif;