Tutorials

Learn web design and programming with our free video and text tutorials.

PHP Switch Statements Tutorial

PHP switch statements allows you to set up a list of conditions with a block of statements for each condition. The switch statement tests the value of one variable and executes the block of statements for the matching variable, or cases.

<?php
$state = "TX";
switch($state){
case "CA";
echo "I live in California";
break;
case "NY";
echo "I live in New York";
break;
case "TX";
echo "I live in Texas.";
break;
}
?>

The code above outputs:

I live in Texas.