14. Switch

If you want to select one of many blocks of code to be executed, use the Switch statement.
The switch statement is used to avoid long blocks of if..elseif..else code.

<?php
	$k=8;
	switch ($k){

		case $k>1 && $k<2:
		echo "one";
		break;
		 
		case 3:
		echo "Three";
		break;
		 
		case 5:
		echo "Five";
		break;
		 
		case 7:
		echo "seven";
		break;
		 
		case 20;
		echo "Twenty";
		break;
		 
		default:
		echo "nothing";
		break;
	}
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s