PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
if ($var=="value 1") {
} else if ($var=="value 2") {
} else if ($var=="value 3") {
else {
}
Where "value 1","value 2","value 3" are simple constant literals (strings, integers, etc) and the variable you are comparing is the same in all the cases.
In your case you're checking if multiple different variables are set -- this is not convertable to a switch.
switch (true) {
case isset($var) :
echo $var;
break;
case isset($var2) :
echo $var2;
break;
}
Just wondering, why would you every want to use that construction? I'm actually suprised the interpretor doesn't barf on that, I wonder if you reported it as a bug if Zend would agree...
if (isset($var)) {
echo $var;
} else if (isset($var2)) {
echo $var2;
}
I can't picture any use... You're not using the default, but if you were that falls into the final else. Perhaps if you needed some very interesting fall-through behavoir?
That's what I thought with this. I've used switches in other places in place of conditionals and they worked fine there, and was curious if it worked with isset() and empty(). I'll be leaving it the way it is if it's not really practical to change it.