0
What is the optimal maximum amount of elseifs in one if statement to manage them easily?
2 Answers
+ 3
you can use as amany as u wish but i suggest the switch is best
+ 2
If you find yourself using a lot of "elseif"s like this
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} elseif (...) {
echo "...";
} elseif (...) {
echo "...";
} elseif (...) {
echo "";
} elseif (...) {
echo "";
} else {
echo "a is smaller than b";
}
?>
then you should look at using switch construction instead:
http://php.net/manual/en/control-structures.switch.php