PHP Switch Statement

PHP Switch Statement, come in handy when you have a lot of conditional statement.A Switch Statement by default consist of a Default output. The Switch Statement Structure are build on Condition “switch()” , Selection of Criteria  ” case()” , to get out of the criteria “break; ” and a default signal.

  • Switch(Switch value) – Is a Switch value , this switch will turn on , when the switch value is true.
  • case(Switch Value) – Which condition group the  Switch Value belongs to.
  • break -Break out of the conditions
  • Default- When no value in the ” Switch Value” matches the condition case

 

Refer the code below for the PHP Switch Source Code


<?php
$a = 'Smart';


switch ($a) {
		case "Poor" :
				echo "If I am ".$a . " I work Harder";
				break;
		case "Slow" :
				echo "If I am ".$a . " I train Harder";
				break;
		case "Rich" :
				echo "If I am ".$a . " I help other";
				break;
		case "Smart" :
				echo "If I am ".$a . " I help other";
				break;
		default :
				echo "no if input";
				break;
			}
?>

Check out PHP Conditional Statement here