PHP Switch Control

Switch statement is used to perform different actions based on differnt conditions.

Switch Statement


<?php

$day=strtoupper(date("D"));
switch($day){
	case "MON":
		echo "Today is Monday.";
		break;
	case "TUE":
		echo "Today is Tuesday.";
		break;
	case "WED":
		echo "Today is Wednesday.";
		break;
	case "THR":
		echo "Today is Thursday.";
		break;
	case "FRI":
		echo "Today is Friday.";
		break;
	case "SAT":
		echo "Today is Saturday.";
		break;
	case "SUN":
		echo "Today is Sunday.";
		break;
	default:
		echo "You entered wrong case!";
	
}
?>
	

Use break to prevent the code from running into the next case automatically. The default statement is used if no match is found.