The switch statement is used to run the various condition in the one block of code. As the word suggests, it switches the statement line by line.
Example
[php]<?php
$favcolor = "seagreen";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
?>[/php]
In the above switch statement, the code checked the condition line by line by looking at the case statement. If anyone of the matches the code executes its echo statement. If none of the matches with the variable $favcolor the end default statement is executed.