I was at work today relaxing on my break, and began to ponder, Switches an d if statements. They are almost literally the same. Like for instance..
<?php
$var = $_GET['variable']
switch ($var)
{
case 1:
echo "This is 1";
break;
case 2:
echo "This is 2";
break;
default;
echo "This is the default";
break;
}
?>
Does the same thing as
<?php
$var = $_GET['variable'];
if($var == 1){
echo "This is 1";
}elseif($var == 2){
echo "This is 2";
}else{
echo "This is the default";
}
?>
I myself prefer If/Else statements, because they seem easier to roll through and browse, then a switch. The only difference between a If/Else statments that I can see is that with an if statement you cancheck to see if something is TRUE/FALSE Where as in a Switch, you are just checking for values. But, back to the point, would it really make difference in which you used?