/*
if (expr) {statement}
Example: This example omits curly braces.
The code is as follows |
Copy Code |
<?php if ($state ==1) echo "haha"; ?> |
To determine whether equality is = = instead of =,asp programmers can often make this error, = is the assignment.
Example: The execution section of this example has three lines and cannot omit curly braces.
The code is as follows |
Copy Code |
<?php if ($state ==1) { echo "haha; echo "<br>"; } ?> |
The second is in addition to if, plus the condition of else, can be explained as "if something happened how to deal with, otherwise how to solve". The syntax is as follows:
if (expr) {statement1} else {Statement2}
Example: The above example is modified to a more complete processing. Where else is due to only one line of instructions, so do not add curly braces
The code is as follows |
Copy Code |
<?php if ($state ==1) { echo "haha"; echo "<br>"; } else{ echo "hehe"; echo "<br>"; } ?> |
The third type is recursive if. else loops, usually used in a variety of decision judgments. It will be several if.. Else take to combine the use of processing.
Look directly at the following example:
The code is as follows |
Copy Code |
<?php if ($a > $b) { echo "A greater than B"; } elseif ($a = = $b) { echo "a equals B"; } else { echo "A is smaller than B"; } ?> |
If.. else loop, to compare A and b two variables. You actually want to use this recursive if. else loop, please use caution, because too many layers of the loop can make the logic of the design problem, or less curly braces and so on, will cause the program to appear inexplicable problems
*/