PHP process control and condition selection are an important part of PHP syntax. if this part cannot be understood thoroughly, we cannot continue learning PHP.
PHP process control and condition selection are an important part of PHP syntax. if this part cannot be understood thoroughly, we cannot continue to learn PHP. Therefore, we must be proficient in using various process condition statements for strategizing! The following comments are important explanations of the syntax. please read them carefully! I need to emphasize that if you use the end method, pay special attention to the semicolon ';' at the end of the statement. due to the limited space, this is only a summative article, in the future, I will give a classic case in the comprehensive instance classification. if there is an error, I am grateful to you for your prompt comment.
Flat view printing?
001 |
// If can exist independently |
015 |
// Multiple if statements |
024 |
// Multiple if statements |
037 |
// Use a colon to replace braces {} in the PHP if statement, but the block statement must end with endif. |
043 |
Elseif (false): // else if () cannot be written here (): |
046 |
Switch ($ conditions) |
048 |
// Execute the case statement block when the expression of the case statement is true. |
051 |
// Add break at the end of a common statement to terminate the execution of the following case statement |
055 |
// Your statement Block |
058 |
//...... There can be N case statements. |
065 |
// Alternative writing method |
066 |
Switch ($ cnditions ): |
071 |
// For loop statement, which is the most complex loop control statement in php, has three conditional expressions. The syntax is as follows: |
073 |
For ($ expr1; $ expr2; $ expr3 ){ |
076 |
// Expr1 is a required parameter. The first conditional expression is executed at the beginning of the first loop. |
077 |
// Expr2 is a required parameter. The second conditional expression is executed at the beginning of each loop to determine whether the loop continues. |
078 |
// Expr3: Required parameter. The third condition expression is executed at the end of each loop, |
079 |
// Statenebt required parameter. The statement that is executed cyclically after the condition is met |
080 |
// Alternative writing method |
081 |
For ($ expr1; $ expr2; $ expr3 ): |
084 |
If (is_array ($ var )) |
086 |
Foreach ($ varas $ key => $ v) |
088 |
// Loop traversal $ var usually $ var is an array |
089 |
// If you enter break, the foreach statement is displayed. |
090 |
// If a continue is encountered, it jumps out of the current loop and continues the next loop. |
092 |
// Alternative writing method |
093 |
Foreach ($ varas $ key => $ v ): |
099 |
// Judge first and then execute |
102 |
// Alternative writing method |
109 |
// Execute the command first and then judge |
112 |
// The break statement and the continue statement are used to control the exit of the process. |
114 |
-- Break jumps out of the entire loop statement |
115 |
-- Continue jumps out of the current loop and continues the next loop |