A switch
statement is not the same as an if/else
statement. Switch statements are looking for specific values. If it finds the value specified in a given case
statement, it runs the code after that case
statement.
The following code:
switch($x)
case 1:
// some stuff
break;
case 2:
// some other stuff
break;
default:
// some more stuff
break;
Is the equivalent of this code:
if($x == 1){
// some stuff
}
elseif($x == 2){
// some other stuff
}
else{
// some more stuff
}
Basically, switch
statements are shortcuts for if/elseif/else
blocks where you're checking for a single variable's equality against a bunch of possibilities.
Since empty()
returns 0 or 1, your first case
will run if $location
is 1 (if $location
is empty) or 0 (if $location
isn't empty). It's almost like you've written the following:
elseif($location == empty($location)){ ...
Make sense? Instead of using a switch
statement, you probably want the following:
if(empty($location)){
// ...
}
elseif($location % 10000 == 0){
// ...
}
// ...