Ten Days Learn the second day of PHP

xiaoxiao2021-03-06  43

Learning purpose: Master PHP process control

1, IF..EEEEEEELSE loop has three structures

The first is only the IF condition, as a simple judgment. Explain that "how to deal with something happens." The syntax is as follows:

IF (expr) {statement}

The EXPR is the condition of judgment, and is usually used as a condition for judging using a logical operation symbol. And Statement is part of the eligible execution section. If the program only has a line, you can omit the braces {}.

Example: This example omits the braces.

Today, it is that it is determined whether or not it is equal to == rather than =, the ASP programmer may make this error, = is assignment.

Example: There are three lines in the execution section of this example, and the braces may not be marked.

";}?>

The second is except for IF, and the conditions of ELSE can be interpreted as "how to process something, otherwise how to solve". The syntax is as follows {statement1} else {statement2} example: The above example is modified to be more complete. Since there is only one line of execution, therefore don't have to add braces.

";} else {echo ""; echo "
";}?>

The third is that the recursive IF..ELSE cycle is usually used in a variety of decision judgments. It takes several IFUSE to merge and use.

Directly look at the example below

$ b) {Echo "a bit B";} elseif ($ A == $ b) {echo "a equal to B";} else {echo "a bit";} ?> The above example only uses two IF..EELSE loops to compare the A and B variables. Be careful when using this recursive IFEELSE cycle, please use it, because too many layers are easy to make the design logic problem, or less bracers, etc., will cause an inexplicable problem. 2, the for loop is only one, there is no change, its syntax is as follows

For (expr1; expr2; expr3) {statement}

Where EXPR1 is the initial value of the condition. EXPR2 is the condition of judgment, usually uses a logical operation symbol (Logical Operators) as a condition of judgment. EXPR3 is used to perform some of the STATEMENT to change the condition, for the next loop judgment, such as plus one .. and so on. And Statement is part of the eligible execution section. If the program only has a line, you can omit the braces {}.

The following example is an example written by for loop.

";}?> 3, switch cycle, usually handled Compound conditions judge, each sub-condition, is a Case instruction section. In practice, if many similar IF instructions can be used, it can be integrated into a Switch loop. Syntax is as follows

Switch (expr) {CASE EXPR1: Statement1; Break; Case EXPR2: Statement2; Break; DEFAULT: STATEMENTN; BREAK;

Where EXPR conditions are usually the variable name. The exprn after CASE usually represents a variable value. After the colon, the part to be performed in accordance with this condition. Note To use the BREAK jump from the loop. Here you need to pay attention to Break; I miss it, default, omitted is ok.

Obviously, the above example is very troublesome with an IF cycle. Of course, when designing, the maximum condition in which the chance is maximized is placed in the forefront, and the conditions that appear are placed at the end, and the execution efficiency of the program can be added. The above example is the same as the chance to occur every day, so it is not necessary to pay attention to the order of conditions.

Today, I said that the database is used to say tomorrow.

转载请注明原文地址:https://www.9cbs.com/read-57589.html

New Post(0)