Switch Statement in PHP - How to use Swich Case in PHP
Switch Statement is used to choose one of the statement from many of choices. It is used to give a menu driven output to the user.
Syntax to use switch case statement in php.
<?php
switch(choice)
{
case label1:
statement;
case label2:
statement;
................
...............
...............
case labelN:
statement;
default:
code which should be execute if any of choice is not matched.
}
?>
Example:
<?php
$code=1;
switch($code)
{
case 1:
echo "Red";
break;
case 2:
echo "Green";
break;
case 3:
echo "Blue";
break;
default:
echo "wrong code";
}
?>
Switch Statement is used to choose one of the statement from many of choices. It is used to give a menu driven output to the user.
Syntax to use switch case statement in php.
<?php
switch(choice)
{
case label1:
statement;
case label2:
statement;
................
...............
...............
case labelN:
statement;
default:
code which should be execute if any of choice is not matched.
}
?>
Example:
<?php
$code=1;
switch($code)
{
case 1:
echo "Red";
break;
case 2:
echo "Green";
break;
case 3:
echo "Blue";
break;
default:
echo "wrong code";
}
?>
{ 0 comments... read them below or add one }
Post a Comment