PHP Programming

Hands On No. 10 : Working with case statement in PHP

Working with case statement in PHP

Syntax

                               

switch (n)
{

case label1:
code to be executed if n=label1;
break;

case label2:
code to be executed if n=label2;
break;

case label3:
code to be executed if n=label3;
break;

...

default:
code to be executed if n is different from all labels;
}

Example
                               

<?php
$car = "Audi";
switch ($car)
{
case "Audi":
echo "Your car name is Audi!";
break;

case "tata":
echo " Your car name is Tata!";
break;

case "ford":
echo " Your car name is Ford!";
break;

default:
echo " Your car name is neither Audi, Tata, nor Ford!";

}
?>