PHP Switch Statement

PHP If Elseif Else Previous Next PHP While Loop


PHP Switch Statement is used to select one of many blocks of code to be executed.

The Switch Statements

Syntax


switch(x){ case value1: // code to be executed break; case value2: // code to be executed breal; case value3: // code to be executed ...... default: // code to be executed if x does not match all value }

Here is the code of switch statement.

Filename: php / switch-statment.php


Code
<?php
// PHP switch statement
$day=date("D");
$full_day=$day."day";
switch($full_day){
    case "Monday":
	    echo "Today is Monday, First day of the week (Hard Day)";
	    break;
    case "Tueday":
	    echo "Today is Tuesday, Second day of the week.";
	    break;
    case "Wedday":
	    echo "Today is Wednesday, Third day of the week.";
	    break;
    case "Thuday":
	    echo "Today is Thursday, Fourth day of the week.";
	    break;
    case "Friday":
	    echo "Today is Friday, Fifth day of the week.";
	    break;
    case "Satday":
	    echo "Today is Saturday, Weekend.";
	    break;
    case "Sunday":
	    echo "Today is Sunday, Holiday Enjoy.";
	    break;		
}
?>

Running Step.


Type Url - https://localhost/php/switch-statment.php


Tags: PHP


Was this helpful ?

Related Code


Popular Code

Latest Code