Monday 1 December 2014

Switch Statement in Php

Structure of the Problem Requirements 

In this programme we will discuss about Switch statement in Php. The switch statement is used to avoid complex nested if else conditions. The structure of the switch statement is very simple we just pass a variable to the switch and test it in different cases. Each case end with break state and each new case start with new number. Here is the source code of this problem which help you in better understanding. 

SOURCE CODE

<html>
<head>
<title>Logical Expressions: Switch</title>
</head>
<body>
<?php 
/* switch
Useful when there are many possible actions based on the value of single variable
*/
$a = 2;
switch ($a) {
case 0: 
echo "a equals 0";
break;
case 1: 
echo "a equals 1";
break;
case 2: 
echo "a equals 2";
break;
default:
echo "a is not 0, 1, or 2";
break;
}
?>
</body>
</html>

OUTPUT OF THE PROGRAM



Switch Statement in Php
Switch Statement in Php

Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment