PHP Switch Statement
by TechVidvan Team
Program 1
<html>
<head><title>PHP Relational Operators</title>
<body>
<center>
<?php
$ch='B';
switch($ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': echo "VOWEL"; break;
default:echo "consonent";
}
// $n=3;
// switch($n)
// {
// case 1:echo "One";break;
// case 5:echo "Five";break;
// case 4:echo "Four";break;
// case 2:echo "Two";break;
// case 3:echo "Three";break;
// default:echo "Invalid Number";
// }
/*
switch(value)
{
case 1: break;
case 2:
case 3:
default:
}
// Vowel Chracter
*/
?>
</center>
</body>
</html>Program 2
<html>
<head><title>PHP Switch case </title>
<body>
<center>
<?php
echo "<br><font color=red size=5>------------Menu---------------</font>";
echo "<br><font color=Blue size=5>1.Addition</font>";
echo "<br><font color=Blue size=5>2.Swap</font>";
echo "<br><font color=Blue size=5>3.Max between two number</font>";
echo "<br><font color=red size=5>---------------------------------</font>";
$choice=3;
switch($choice)
{
case 1 :
{
$a=50;
$b=20;
$c=$a+$b;
echo "<br>Addition of ".$a." and ".$b." is ".$c;
break;
}
case 2:
{
$a=50;
$b=20;
echo "<br>Before Sawping ".$a." and ".$b;
$c=$a;
$a=$b;
$b=$c;
echo "<br>After Sawping ".$a." and ".$b;
break;
}
case 3:
{
$a=70;
$b=30;
$c=$a+$b;
echo "<br>bAddition of ".$a. " and ".$b." is ".$c;
break;
}
default: echo "Invalid choice";
}
?>
</center>
</body>
</html>
Tags: PHPphp practicalphp programphp switch case statementphp switch statementswitch case statement in phpswitch conditional statement in phpswitch statementswitch statement in php
TechVidvan Team
TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.