[SOLVED] Switch Statement Evaluation
Posted: Thu Mar 03, 2005 3:30 pm
Do switch statements evaluate a variable and compare it's value regardless of whether or not it's set? And, if so, do you need to wrap the switch statement with an if statement to avoid this?
For example:
If the GO! link is clicked (or, upon initial loading, for that matter):
So, do you have to wrap the switch statement to get it to work the way you expect, or am I missing something?
Eg:
For example:
Code: Select all
<?php
//switch.php
switch ($_POSTї'a']) {
case '1':
echo "ONE!<br>";
break;
default:
echo "DEFAULT!<br>";
break;
}
if (isset($_GETї'b'])) {
echo "BEE!<br>";
}
echo "<a href="switch.php?b=go">GO!</a>";
?>Code: Select all
DEFAULT!Eg:
Code: Select all
<?php
//switch.php
if (isset($_POSTї'a'])) {
switch ($_POSTї'a']) {
case '1':
echo "ONE!<br>";
break;
default:
echo "DEFAULT!<br>";
break;
}
}
if (isset($_GETї'b'])) {
echo "BEE!<br>";
}
echo "<a href="switch.php?b=go">GO!</a>";
?>