PHP Switch Statements

Consider that you have many conditions, rather than doing "ifelse" you can use switch statements and php execute it faster than ifelse statements

Syntax


<?php
switch (conditions) {
case val1:
	executed if conditions matched with val1.
  break;
case val2:
        executed if conditions matched with val2.
  break;
default:
  code to be executed if none of the above conditions satisfy.
}
?>

Example

<?php
$fruits = "Mango";
switch ($fruits) {
    case "Grapes":
        echo "I Like Grapes";
        break;
    case "Mango":
        echo "I Like Mango";
        break;
    case "Orange":
        echo "I Like Orange";
        break;
    default:
        echo "No fruits for me.";
        break;
}?>

//Output: I Like Mango
Submit an Idea
  Thank you for your valuable feedback.
Your E-mail (optional):
Select Option:
Description:
 
Feedback
Your Name / email address
Feedback as
Your feedback
close
Quickly sign in with:

Create a FATALWEB account here:

First name:

Last name:

E-mail address:

Join Fatalweb

Already have a fatalweb account? Log in here