Three major process controls for PHP programs
① sequential control (top to bottom, left to right)
② Branch Control
if (conditional expression) {
N Multiple statements
}else if (conditional expression) {
N Multiple statements
}else if (conditional expression) {
//.
}//there may be more else if
else{
}
U Switch Branch statement
BASIC syntax structure
switch ( expression ) {
Case Constants 1:
//n Multi-statement ;
Break
Case Constants 2:
//n Multi-statement
Break
Default
//n Multi-statement ;
Break
}
u types of constants (int, float, string , boolean, and null
default you can put it anywhere.
The right side will output hello12 .
conclusion: First, according to Case order to match if none of them matches
to, then execute default , until you encounter Break or }
Application scenario: When our branch is a few points (such as judging the direction of the tank), we should use Swtich, if your branch is a few areas (range) of the judgment, then consider using IF.
③ Cycle Control Flow
For ( Cyclic initial value ; conditions of the cycle ; Step Size ){
//n Multi-statement ;
}
While ( loop condition ) {
// Loop Body , Statement
}
do{
// Loop Body
}while ( cyclic conditions );
42, We follow the normal thinking should be guaranteed to accept the data when the $_request[' parameters ' to and submit the data page The HTML element name to be consistent. If not, the notice prompt appears. at the same time we accept that the data is null, equivalent to "".
//$_request This method can accept the user's post or GET request data
43. Break and Continue
U Loop-related statement-break
Basic concept: Indicates the end of the current for, while, do. While,switch, process , you can give a number that indicates exiting to the first layer .
$i = 0;
while (+ + $i) {
Switch ($i) {
Case 5:
echo "Quit At5<br/>";
Break
Case 10:
echo "Quitat 10<br/>";
Break 2;
Default
Break
}
}
echo ' $i = '. $i;
The result is:
Quit at 5
Quit at 10
$i =10
From the above case, we get a few conclusions:
1. Break statement jumps out of layer 1 by default
2. The number after the break statement cannot exceed the number of loop layers that can actually be jumped out, otherwise it will be reported fatalerror
? Circular related Statements-continue
Basic concept: Continue is used to end this cycle of the remaining code, start a new cycle (if the condition is true, continue to execute),continue can also be followed by a number, indicating a restart from the first few cycles
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Three major process controls for PHP programs