In PHP if & elseif is something i was always using when in fact a simple switch would have done the job and looked cleaner.
Looking at the following Switch and if elseif code, they do the same thing.
$status = 1;
switch ($status) {
case 0:
echo "Offline";
break;
case 1:
echo "Online";
break;
case 2:
echo "Away";
break;
}$status = 1;
if($status = 0){
echo "Offline";
} elseif ($status = 1) {
echo "Online";
} else {
echo "Away";
}We can minify the if elseif, although it can get confusing especially if you come to edit it in the future.
$status = 1;
if($status = 0){echo "Offline";} elseif ($status = 1) {echo "Online";} else {echo "Away";};Switch or if elseif?
Its going to come down to how many options you will have, up to 3 different outcomes in an if else seems to be the limit for me, more than that and a switch just seems cleaner and easier to look at and edit rather than a massive nest of if & elseif.