Blog Introductions
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. Php Controls Flow Switch Statements | Php tutorials Bestitworriors
Php Controls Flow Switch Statements
Php Controls Flow Switch Statements | Php tutorials Bestitworriors - Switch is used to execute one block from many blocks.In if-else part we see that we use in certein condation is true the execute the specifi if condation part if not true the execute the else part.In Switch we have many block but execute only one at one time if condation not match with any condation the execute the default part.Switch is same as if-else the work is same but little bit difference in code and structure but almost same woke.
Some Key Points of Switch
- Execute only block from many blocks
- It can save time then having multipule if-else
- Switch have same work like if-else
- Switch also execute specific condation match
- Inside switch case block is use to match the condation
- IF condation do not match then execute default code block
- Switch pass parameter to compare case block
- You can have multiple switch for specific criteria
Code
< ?php
$parameter = 10;
switch($parameter) {
case
1:
echo
"Your Parameter is".$parameter;
break;
case
2:
echo
"Your Parameter is".$parameter;
break;
case
3:
echo
"Your Parameter is".$parameter;
break;
case
4:
echo
"Your Parameter is".$parameter;
break;
case
5:
echo
"Your Parameter is".$parameter;
break;
case
6:
echo
"Your Parameter is".$parameter;
break;
case
7:
echo
"Your Parameter is".$parameter;
break;
case
8:
echo
"Your Parameter is".$parameter;
break;
case
9:
echo
"Your Parameter is".$parameter;
break;
case
10:
echo
"Your Parameter is".$parameter;
break;
default:
echo
"Your Parameter is greater then 10";
}
echo
"<br>";
$month = "january";
switch($month) {
case
"january":
echo
"Today month is ".$month;
break;
case
"feburary":
echo
"Today month is ".$month;
break;
case
"march":
echo
"Today month is ".$month;
break;
case
"april":
echo
"Today month is ".$month;
break;
case
"may":
echo
"Today month is ".$month;
break;
case
"june":
echo
"Today month is ".$month;
break;
default:
echo
"Your month do not match";
}
? >
OutPut
Your Parameter is 10
Today month is january
Today month is january
0 Comments