Conditional Structure-if{... }else{... }
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:
<?PHPIF (condition) {//Assign server Dry task a}else{//Assign server to dry task b}?>
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-if (...) {... }else if (... ){... }
php "if{...}" else if () {...} " Syntax, as follows:
<?PHPIF (Condition one) {//Assign server Dry task A}else if (condition two) {//Assign server to 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.
Strippiece structure-if (...) {...} else if (...) {}else{...}
"If (...) in PHP" {...} else if (...) {...} else{...} " Syntax, as follows:
<?PHPIF (Condition one) {//Assign server Dry task A}else if (condition two) {//Assign server to dry task b}else{//Assign server to dry task c}?>
by condition One , if the return value is Boolean true, then execute task A, if the return value is False, then the condition two , if the return value is Boolean true, then execute task B, otherwise neither perform task A nor perform task B, execute task c.
conditional structure-switch...case ...
The "Switch...case ..." syntax in PHP is as follows:
<?phpswitch (condition) {Case Condition value one://task one break; case condition Value Two://Task two break;default://Default 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 (which is followed by a specific example), using the switch statement to avoid lengthy "if." else if: Else "code block.
* The function 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) {//Perform 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.
loop structure in PHP-do while loop statement
There is another way of looping statements in PHP: The Do...while Loop statement syntax is as follows:
<?phpdo{//Perform task}while (condition)?>
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.
(1) The difference between the while and the do...while statements of the loop structure in PHP
The difference between the while and the Do...while Loop statement is:
While first judging whether the condition is established, after the execution cycle;
Do...while perform a task before deciding whether to continue the loop;
This means that 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.
(2) Examples of the advantages of using the Do...while statement of the cyclic structure in PHP
While and Do...while can be selected depending on the situation.
Suppose there is a chess game, the first to roll the dice, if not 6, the step forward dice points;
If it is 6, the step of the point of the forward dice, and can be thrown again.
650) this.width=650; "src=" Http://note.youdao.com/yws/res/10018/074C05E1542E4A428754831A7922010E "style=" Margin-top:8px;height:443.125px;color:rgb (51,51,51); font-size:13px;line-height:1.6;width:841.256px; Background-color:rgb (226,228,230); "alt=" 074c05e1542e4a428754831a7922010e "/>
from The structure and readability of the code is more appropriate for using do...while in this example.
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:
<?phpfor (initialize; cycle condition; increment item) {//Perform task}?>
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.
650) this.width=650; "src=" Http://note.youdao.com/yws/res/10025/AA1A4C636E114E7EB42D8E1F75C9EE6B "style=" margin-top:8px;height:482.313px;width:840.255px; "alt=" aa1a4c636e114e7eb42d8e1f75c9ee6b "/>
the Foreach Loop statement for the loop structure in PHP (task one)
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
<?php foreach (array as value) {//task performed}?>
(2) Remove the mark and value at the same time
<?phpforeach (array as Subscript = = value) {//task performed}?>
(1) Do not remove the array traversal of the tag
650) this.width=650; "src=" Http://note.youdao.com/yws/res/10031/22586BF897E74192AFC48ED0EDFD2E5F "style=" margin-top:8px;height:490.5px;width:575.854px; "alt=" 22586bf897e74192afc48ed0edfd2e5f "/>
(2) Remove the array traversal of the tag
650) this.width=650; "src=" Http://note.youdao.com/yws/res/10037/9D862974EAF04924B5C5E8B3E66A9A0A "style=" margin-top:8px;height:468.5px;width:553.498px; "alt=" 9d862974eaf04924b5c5e8b3e66a9a0a "/>
This article from "I am a phper, simple and naïve" blog, please be sure to keep this source http://thinkforphp.blog.51cto.com/8733331/1784628
PHP-Logic syntax