The switch is used to execute dissimilar actions based on dissimilar conditions.
Syntax:-
switch (n) {
case label1:
Execution code if n=label1;
break;
case label2:
Execution code if n=label2;
break;
case label3:
Execution code if n=label3;
break;

default:
Execution code if n is different from all labels;
}
Example:-
<?php
$week = “monday”;

switch ($week) {
case “sunday”:
echo “Today is Sunday!”;
break;
case “Monday”:
echo “Today is monday!”;
break;
case “Tuesday”:
echo “today is Tuesday!”;
break;
default:
echo ” Today is Wednesday!”;
}
?>

Categories: PHP

0 thoughts on “PHP Switch”

Leave a Reply

Related Article

Blog

PHP Magic Methods

__get()/__set() – These are magic getters and setters for getting and putting values for class properties created dynamically. __isset() – This magic method will be invoked automatically while checking whether a required overloaded property is Read more…

Blog

WordPress Upgrade

The WordPress upgrade released time to time. We provide a WordPress upgrade, content management and maintenance services at affordable price. WordPress upgrade fixes bugs, runs cleaner, faster, and is more secure and stable. We will Read more…

Blog

Magento 2 Upload image in product

If you are trying to upload image on respective product by script then below code will help you to solve this issue. by this code you can set product thumbnail, small and large image. $objectManager Read more…