In this tutorial I will give a brief lesson on the PHP switch statement.
Keep in mind that I don't practice the proper 'formatting' of code (like indenting).
It doesn't matter, but it does make things easier for big projects.



This will check to see what $color is and return the proper results.
If the $color switch is 'red', then print "Red is a cool color!".
If the $color switch is 'green', then print "Green is also a cool color!".
If the $color switch is 'blue', then print "Blue is an over-rated color.".
And if the $color switch isn't defined, then print "That color is $color.".

Note: At the end of a case use 'break;' end that case.

[Back To PHP Tutorials]
Free Web Hosting