PHP Switch Case Statement

In PHP, switch statement is a variant of the if-else combination and is used when we need to compare a variable against a large number of values depending on the value that is matched.

Syntax

In case of if...elseif...else statement same variable is compared again and again with different values. This looks quite cumbersome, specially when later want to change the expression used in all of the tests. For this purpose, PHP provides an easy way to run these types of tests: the switch statement.

PHP Switch Case Statement Example

This will produce following result: