Originally posted by MrAlaska
For one thing, switch statements are PERTIER! Just look at it, see how nice it looks?
It also makes it easier for someone else to debug the code. One glance and you can see the switch is on the same variable, instead of reading through each if statement to make sure you aren't missing anything.
With a load of elseif statements there's no warning that the same thing will be tested again, so it's "get the value of $page and compare it to 'index'. Are they the same? No. Follow the else. Get the value of $page and compare it to 'admins'. Are they the same? No. Follow the else...."
With a switch statement the parser is able to build up a table of what things $page will be tested against in advance. When it comes time to run the switch, it only needs to fetch the value of $page once and go through this table to find a match.
In short, a switch statement is like a single if statement that can branch off in a lot of directions, instead of a series of if statements, with only two branches each, that might all have to be checked through.
How smart PHP is with this is open to question and experiment, but C compilers at least implement a switch table directly in machine code, which is a lot faster than the long series of tests and jumps that a series of if statements would produce.