In PHP,the Switch statement is used to perform different actions based on different conditions.The Switch statement works like this, it takes a single variable as input and then
checks it against all the different cases that you set up for switch
statement. Instead of having to check that variable one at a time, as it
goes through many of If Statements, the Switch statement only has to
check one time.
Switch Statement example:
Let’s take a example, the single variable will be $company and the cases will be: Honda, Suzuki, Hero, Bajaj.
Switch Statement example:
Let’s take a example, the single variable will be $company and the cases will be: Honda, Suzuki, Hero, Bajaj.
| <?php $company = “Hero”; echo “Bikes of $company<br/>”; switch ($company){ case “Honda”: echo “its very costly”; break; case “Suzuki”: echo “buy a hayabusa bike”; break; case “Hero”: echo “best reseller product”; break; case “Bajaj”: echo “buy limited bikes”; break; } ?> |
No comments:
Post a Comment