1. There are four main types of flow control statements: if, ii...else, elseif (sometimes it can also be written as else if), and switch. The statement format in PHP is:
if (condition is met) {execution statement}
if (condition is met) {execution statement} else {execution statement}
if (condition Satisfy) {Execution statement} elseif {Execution statement} elseif {Execution statement} ..... else {Execution statement}
switch (condition) {case 1: statement; break;
case 2:Statement;break;
case 3:
## default: }if:There is only one condition If...else: There are two conditions elseif: There are multiple conditions Switch: There are multiple conditions When there are multiple conditions, the elseif and switch statements have the same effect. However, in order to avoid complicated and lengthy statements, use switch statements2. There are three main types of loop control statements: while, for, and do while. For example, to output all integers less than 5, the statement format in PHP is:*******while语句******* $i = 0; while($i<5) { echo $i; $i++; } *******for语句******* for($i = 0;$i < 5;$i++) { echo $i; } ******do while语句******* $i = 0; do { echo $i; $i++; }while($i<5);
The above is the detailed content of Detailed explanation of flow control statements and loop control statements in PHP. For more information, please follow other related articles on the PHP Chinese website!