PHP reading notes (5)-structure statements, PHP reading notes
PHP structure Statements
Sequential structure
The sequential structure is like a straight line, which is carried down in order. The code we write is executed by default in the order structure.
The if...else of the conditional structure ...
The conditional structure is like a fork that can walk to the left or to the right. For example, in the bathroom, we know our sex, this time we need to according to the bathroom conditions, the left men's room, the right woman's toilet, or just the opposite, where sex is the condition of the conditional structure. For example, now the scores are popular using A, B, C to grade, assuming that the test score is 93, you can set it to level A, the test score is 87, you can set it to level B, where the score interval is the condition of the conditional structure.
The "If...else ..." syntax in PHP is as follows:
1
PHP2if(condition) {3 // Assignment Server Dry Task a4 }Else {5 // Assignment Server dry task B6}7 ? >
By conditional judgment, if the return value is Boolean true, then task A is executed, and if the return value is False, then task B is executed.
Conditional structure of the if...else if ...
The "If...else If ..." Syntax in PHP is as follows:
PHPif(condition one) { // Assign server to dry task a}elseif( Condition II) { // Assignment Server dry task B}?>
by condition One , if the return value is a Boolean value of True, then execute task A, if the return value is false, then the condition two is evaluated, if the return value is Boolean true, then the task B is executed, otherwise neither task A nor task B is executed. The server will continue to perform other tasks.
The switch...case of the conditional structure ...
The "Switch...case ..." syntax in PHP is as follows:
1
PHP 2switch (condition) 3{ 4 Case Condition value one: 5 // Task One 6 Break 7 Case Condition value two: 8 // task two 9 Break ; Ten Default:one-by-one // defaults task (?>)
First judge the condition, if the return value of the condition is the condition value one, then perform task one, if the value returned by the condition is the condition value two, then perform task two, if the return value of the condition is neither the condition value nor the condition value two, the default task is executed. The effect of break is to end the switch and use the switch statement to avoid lengthy "if." else if: Else "code block.
The effect of break is to prevent the code from entering the next case to continue execution.
Loop structure in PHP while loop statement
The loop structure is like running a football field in a circle and running a circle. In other words, a task is performed repeatedly under the conditions that are met. Like 400.1-meter laps of the runway, run 800 meters, then run 2 laps, when running the first lap and then run the second lap, the second lap end has reached 800 meters, stop running.
In PHP, the while loop statement is as follows:
PHPwhile(condition) { // Execute task }?>
First, determine whether a condition is compliant (the conditional return value is true), perform the task if it is met, perform the task, and then determine whether the condition meets the requirements, and then repeat the task, or end the task.
Do and loop statements for the loop structure in PHP
There is another way of looping statements in PHP: The Do...while Loop statement syntax is as follows:
1
PHP2do3 // perform task 4 }while(conditional) 5 ?>
Perform the task first (the while statement in the previous section is to determine whether the condition is set up, then perform the task), perform the task, determine whether a condition is met (the conditional return value is true), if the task is executed again, the completion of the task, continue to determine the condition.
The difference between the while and the do...while statements of the cyclic structure in PHP
The difference between the while and the Do...while Loop statement is that while the time first determines whether the condition is true, then executes the loop, Do...while executes the task once and then determines whether to continue the loop, that is, the do...while will perform at least one task. When the condition is false, the task in the while is not executed once, and the task in Do...while executes 1 times.
A For loop statement for the loop structure in PHP
There is also a looping statement in PHP, with the FOR Loop statement structured as follows:
1
PHP2for(initialize; loop condition; increment item) {3 // perform task 4} 5 ?>
For statement, initialization is evaluated unconditionally before the loop begins, and the loop condition is evaluated before each cycle begins. If the value is TRUE, the loop continues, executing the Loop body statement (performing the task). If the value is FALSE, the loop is terminated. The increment item is evaluated after each loop (execution). It is often used to loop the number of times a code block is specified.
The Foreach Loop statement for the loop structure in PHP
In PHP, the Foreach Loop statement, commonly used to iterate over an array, is generally used in two ways: Do not remove the label, remove the label.
(1) value only, do not remove the label
1
PHP2 foreach as value) {3// tasks performed 4 }5 ?>
(2) Remove the mark and value at the same time
1
PHP2foreach as Subscript = = value) {3 // performed task 4 }5 ?>
Previous section: PHP reading Notes (4)-Operators
http://www.bkjia.com/PHPjc/1138819.html www.bkjia.com true http://www.bkjia.com/PHPjc/1138819.html techarticle PHP Reading notes (5)-structure statements, PHP reading NOTES PHP structure statements The order structure of the structures is like a straight line, which is executed down in order. The code we write by default is ...