Lesson 20 of 3067%
(Progress persistence is disabled until Phase 9)
PHP
Beginner
Switch
Learn about Switch in PHP.
PHP is a powerful server-side language. In this lesson, we will cover Switch.
Real code examples
<?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
default:
echo "Your favorite color is neither red nor blue!";
}
?>
Common mistakes
Make sure you include the <?php tag when writing PHP!
Try It Yourself
You can experiment with this in the Playground.