Three major process controls for PHP programs
① sequential control (top to bottom). From 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 a lot of other else if
else{
}
U Switch Branch statement
The basic grammatical 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, assuming none of the matches
to, then run default , until you encounter Break or }
Application scenario: When our branch is a few points (for example, to infer the direction of a tank), you should use Swtich, assuming that your branch is inferred from several regions (ranges). 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[' " " to and submit the data page The HTML element name to be consistent. If the assumptions are inconsistent, a notice prompt appears.
The data we accept at the same time 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
Main concept: Indicates the end of the current for, while, do. While,switch, process , can give a number, indicating exit 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 jump out. Otherwise. Will report FatalError
? Circular related Statements-continue
Basic concept: The Continue is used to end the remainder of this cycle of code. Start a new cycle (assuming the condition is true and continue running),continue can also be followed by numbers, indicating that the first cycle starts again
Three major process controls for PHP programs