How to use switch case in php with example tutorial

How to define switch case inside php program with multiple cases values.

Switch case statement is used to select one value compare to another. For example developer can compare two or multiple values using switch case and perform various operation when the case match to the given value. So here is the complete step by step tutorial for How to use switch case in php with example tutorial.

android-project-download-code-button

Syntax of Switch case :

switch (A) {
 case Value1:
 code will be execute on A = Value1;
 break;
 case Value2:
 code will be execute on A = Value2;
 break;
 case Value3:
 code will be execute on A = Value3;
 break;
 default:
 code to be executed if n is different from all labels;
}

How to use switch case in php with example tutorial.

Code for switch-case-program.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>How to use switch case in php with example tutorial</title>
</head>

<body>

<?php

$one = 12;

switch($one)
 {
 case 10 :
 echo '<h3> Value is 10 </h3>';
 break;
 
 case 11 :
 echo '<h3> Value is 11 </h3>';
 break;
 
 case 12 :
 echo '<h3> Value is 12 </h3>';
 break;
 
 case 13 :
 echo '<h3> Value is 13 </h3>';
 break;
 
 default:
 echo '<h3> Value not found </h3>';
 
 }

?>
</body>
</html>

Screenshot:

How to use switch case in php with example tutorial

Click here to download How to use switch case in php with example tutorial project file.

Leave a Reply

Your email address will not be published. Required fields are marked *