Switch statement is a type of a selection control statement that exists in most of the programming languages. When we have two options we use if else statement but when we have more than two option we use switch option although that can also be handled by if else.
Switch statement in PHP:
In php switch statement can also be used for the same purpose. It allows control to transfer in different statement depending on the value that you have given. Value may be an integer or an enumeration. The syntax of the switch statement is
In this code we have one choice variable intialized with ROCK value and we have different case statement code to check the given value and run that statement and displays result.
$choice = "Rock";
print "Pop not Rock";
print "Rap and not Rock";
print "Jazz not Rock";
print "Rock music";
Above is a simple code to use switch statement in php.
This simple article tells that how we can use switch statement in php.
Switch statement in php