Three major process controls for PHP programs
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 constant 1:
n multiple statements;
Break
Case constant 2:
N Multiple statements
Break
Default
n multiple statements;
Break
}
Types of U constants (int, float, string, Boolean, and null
The default is wherever it's placed.
The right side will output hello12.
Conclusion: Match in case order first, if none match
To execute default until a break or} is encountered.
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; loop condition; step) {
n multiple statements;
}
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 the 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
;
Break
Case 10:
Echo Quitat 10
;
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
Ø Cyclic correlation statement-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
http://www.bkjia.com/PHPjc/1040916.html www.bkjia.com true http://www.bkjia.com/PHPjc/1040916.html techarticle PHP program three major flow control PHP program three major flow control ① order control (from top to bottom, from left to right) ② branch control if (conditional expression) {//n Multi-statement}else if (conditional expression ...