Back in the old day when I first know how to program in php, I always used if-else statement. Sometimes, it gets so long that I couldn’t even keep track of how many if or else, and where the else supposed to be closed. I have no idea. It’s like a jungle of if else in my file. Since I started using switch() function, my codes are much cleaner when I need multiple conditions applied on one variable. I love it. If you only have 1 condition, it’s not worth using this function.
This was my if-else statements before I used switch function:
You will see how switch function can save you a lot of typing and it looks much cleaner on you page.
I have a habit of writing open and close php tag when I start my php codes. If you don’t need the <?php tag, you can just ignore it.