Conditional Statements is using to, execute some code if a condition is true and another code if the condition is false.
Syntax:
switch (variable)
{
case value1:
Program will execute if ‘variable’ value is equal to ‘value1’;
break;
case value2:
Program will execute executed if ‘variable’ value is equal to ‘value2’;
break;
default:
Program will execute if ‘variable’ value is different from both ‘value1’ and ‘value2’;
}
<?php
$a = 2;
switch($a} {
case 1:
echo “The value of a is 1”;
break;
case 2:
echo “The value of a is 2”;
break;
default:
echo “The value of a is not 1 or 2”;
break;
}
?>
Output : The value of a is 2.