PHP Switch


PHP Switch :– Switch control is helpful in comparing values against multiple conditions in order to execute matching statement as per the program requirement.

When switch expression evaluate a value then immediately control enters inside switch block and searches for a match value equivalent to expression value ; obvious the corresponding statement will be executed.

This scenerio can be easily understood by below mentioned php script.


PHP Switch | Case | Example

Let us take an example to understand how does switch case works. Here we can see that $name is variable name and it’s value is 20 which is passed as to switch parameter and the corresponding case condition is executed. So the output we got number is 20 shown in below screenshot.

PHP Switch Case Example

<?php

$name=20;
switch($name){
	
	case 20:
	  echo "number is 20";
	  break;
	case 30:
      echo "number is 30";	
	  break;
    default :
     echo "no value";	
	 break;
}
?>



Advertisements

Add Comment

📖 Read More