Example -
Switch statement can be used to execute the particular block
of code based upon some condition.
Code and Syntax –
<?php
$ind="one";
switch ($ind)
{
case "one":
echo "You selected one!";
break;
case "two":
echo "You selected two!";
break;
default:
echo "you selected neither one or two!";
}
?>
$ind="one";
switch ($ind)
{
case "one":
echo "You selected one!";
break;
case "two":
echo "You selected two!";
break;
default:
echo "you selected neither one or two!";
}
?>
Explanation
–
Above code will print one. If you have $ind =”233” then you will
have output as "you selected neither
one or two!";
This is how you can use the switch statement in
PHP.
For more
php questions and answers, dumps,tutorials for beginners and experienced people
visit http://www.top-php-interview-questions.blogspot.in If you find any errors while executing this
program, you can make your comments or mail me at reply2sagar@gmail.com
No comments:
Post a Comment