PHP switch condition, here two scenarios are written , one for given case and other for default case.
Scenarios 1
<!DOCTYPE html>
<html>
<body>
<?php
$SelectPHPversion= "PHP 7.1";
switch ($SelectPHPversion) {
case "PHP 7.1":
echo "System running on PHP 7.1";
break;
case "blue":
echo "System running on PHP 7";
break;
case "green":
echo "System running on PHP 6.1";
break;
default:
echo "System running on PHP 5.5";
}
?>
</body>
</html>
Output :
System running on PHP 7.1
Second Scenario :
<!DOCTYPE html>
<html>
<body>
<?php
$SelectPHPversion= "PHP 4";
switch ($SelectPHPversion) {
case "PHP 7.1":
echo "System running on PHP 7.1";
break;
case "blue":
echo "System running on PHP 7";
break;
case "green":
echo "System running on PHP 6.1";
break;
default:
echo "System running on PHP 5.5";
}
?>
</body>
</html>
Output :
System running on PHP 5.5
here default selection executed due to non availability of selected switch case
Scenarios 1
<!DOCTYPE html>
<html>
<body>
<?php
$SelectPHPversion= "PHP 7.1";
switch ($SelectPHPversion) {
case "PHP 7.1":
echo "System running on PHP 7.1";
break;
case "blue":
echo "System running on PHP 7";
break;
case "green":
echo "System running on PHP 6.1";
break;
default:
echo "System running on PHP 5.5";
}
?>
</body>
</html>
Output :
System running on PHP 7.1
Second Scenario :
<!DOCTYPE html>
<html>
<body>
<?php
$SelectPHPversion= "PHP 4";
switch ($SelectPHPversion) {
case "PHP 7.1":
echo "System running on PHP 7.1";
break;
case "blue":
echo "System running on PHP 7";
break;
case "green":
echo "System running on PHP 6.1";
break;
default:
echo "System running on PHP 5.5";
}
?>
</body>
</html>
Output :
System running on PHP 5.5
here default selection executed due to non availability of selected switch case
Comments