Core PHP PHP

PHP 5 Switch Statement

PHP 5 switch Statement

PHP switch statement is used for different actions on the base of different conditions. The switch statement is similar if statements on the same expression. When we have multiple options and we wants to select only, other words we can say that switch statement execute only one condition.

 

PHP switch Statement

Switch statement is used to select one of many blocks of code for execution.

Syntax

switch (x) {
case 1:
executed if x=1;
break;
case 2:
executed if x=2;
break;
case 3:
executed if n=3;
break;

default:
executed if x is different from all conditions;
}

Example

<?php
$name = “shyam”;

switch ($name) {
case “shyam”:
echo “Hi shyam how r u ?”;
break;
case “suresh”:
echo ” Hi suresh how r u ?”;
break;
case “sukesh”:
echo ” Hi sukesh how r u ?”;
break;
default:
echo “Hi everyone how r u ?”;
}
?>

Leave a Reply

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