Three main flow control of PHP program
① sequential control (from 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 grammatical structure
switch (expression) {
CASE constant 1:
n multiple statements;
Break
Case constant 2:
N Multiple statements
Break
Default
n multiple statements;
Break
}
the type of the U constant (int, float, string, Boolean, and null
You can keep the default wherever you go.
The right side will output hello12.
Conclusion: first match according to case order, if none of them match
, the default is executed until a break is encountered or}
Application scenario: When our branch is a few points (for example, to determine the direction of a tank), you should use Swtich, and if your branch is judged by several areas (ranges), consider using IF.
③ Cycle Control Process
For (cyclic initial value; loop condition; step size) {
n multiple statements;
}
while (loop condition) {
Loop body, statement
}
do{
Circulation body
}while (cyclic conditions);
42, we in accordance with the normal thinking should be guaranteed to accept the data when $_request[' parameters ' to the submission of data page to give the name of the HTML element to be consistent. If it is inconsistent, a notice prompt appears. And the data we accept is null, equivalent to "".
$_request This method can accept the user's post or GET request data
43. Break and Continue
U -Loop related statements-break
Basic concept: Represents the end of the current for, while, do. While, switch, process, you can give a number that represents the exit to the first level.
$i = 0;
while (+ + $i) {
Switch ($i) {
Case 5:
Echo Quit AT5
;
Break
Case 10:
Echo Quitat 10
;
Break 2;
Default
Break
}
}
echo ' $i = '. $i;
The result:
Quit at 5
Quit at 10
$i =10
From the above case, we have several conclusions:
1. Break statement default jump out of 1 layer
2. The number after the break statement, can not exceed the actual number of loops to jump out, otherwise, will report FatalError
Ø Circular related statements-continue
Basic concept: Continue is used to end this cycle of remaining code, to start a new cycle (if the condition is true, continue to execute), continue can also be followed by a number, indicating from the first several loops restart