1. Sequential control
2. Condition control
Two if else and switch
(1) if; if else; If else if ... else
$day _11_11= false;
if($day _11_11){
Echo"today is Singles Day .";
}Else{
Echo"today is not Singles Day .";
}
(2) switch (variable) {
Case value1:
Statement1;
Break;//break cannot be lost, otherwise all cases will be executed.
Case value2:
Statement2;
Break
.....
Default
Statement2;
Break
$weekday= Strftime ("%A");
Switch($weekday){
Case"Monday":
Echo"Today is Monday";
Break;
Case"Tuesday":
Echo"Today is Tuesday";
Break;
Case"Wednesday":
Echo"Today is Wednesday";
Break;
Case"Thursday":
Echo"Today is Thursday";
Break;
Case"Friday":
Echo"Today is Friday";
Break;
Case"Saturday":
Echo"Today is Saturday";
Break;
default:
Echo"Go out";
Break;
}
3. Cycle control
Four while do...while for foreach
while (condition) {
Statement
}
do{
Statement
}while (condition);//Don't forget;
while (condition) {
Statement
}
for (EXPR1;EXPR2;EXPR3) {
Statement
}
==============================
Highlight the Foreach Loop
foreach is best at working with arrays
The syntax is foreach (array as $value) {//each time the loop assigns the value of the array element to $value and then the array pointer moves back
Statement
}
or foreach (array as $key = = $value) {//$key is an index $value is the array element value under the corresponding index
Statement
}
$price= Array("Lenono"="200dollars","Dell"="100dollars","ASUS"="Dollars");
foreach($price as$key=$value){
Echothe price of$key is$value"."<br>";
}
Note: An error occurs when using a Foreach loop for a variable of a non-array type, so you should use the Is_array () function to determine if the variable is an array.
=======================================================
Use break to jump out of a loop directly when a condition is met.
Using continue, you can skip this loop and continue executing the loop statement when a certain condition is met.
This article is from the "thick Product Thin Hair" blog, please make sure to keep this source http://joedlut.blog.51cto.com/6570198/1852969
PHP Rookie (2) PHP Process Control