Control Structure
1. If condition Judgment statement
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/> <?php $a = 10; if ($a > 0) {echo ' integer greater than 0 ';} echo ' <br/> '; if ($a > 0) {echo ' integer greater than 0 ';} else if ($a < 0) {echo ' integer is less than 0 ';} else {echo ' integer equals zero ';}?>
2. Switch statement
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/> <?php $role = ' admin '; Switch ($role) {case ' admin ': echo ' admin ', break, case ' user ': Echo ' ordinary users '; break, Case ' guest ': echo ' visitor '; break; Defa Ult:echo ' visitors '; Break }?>
3. While loop statement
<?php $a = 10; while ($a > 0) {echo $a-; Echo ' <br> ';}?>
4. Do and loop statements
<?php $a = 10; Do {echo $a--echo ' <br/> ',} while ($a > 0)?>
5. For loop statements
<?php for ($a = 0; $a < $a + +) {echo $a; echo ' <br/> ';}?>
6. Break statement
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/> <?php for ($a = 0; $a < $a + +) {echo $a ; Echo ' <br/> '; if ($a ==5) {break;//terminates the loop, but executes the statement following the loop}} echo ' Loop end ';?>
7. Exit statement
<?php for ($a = 0; $a <, $a + +) {echo $a; echo ' <br/> '; if ($a ==5) {exit;//exit directly, the statement following the loop does not execute}} echo ' Loop end '; ?>
8. Continue statements
<?php for ($a = 0; $a <; $a + +) {echo $a; echo ' <br/> '; if ($a ==5) {Co ntinue;//end this cycle, continue the next loop, the statement behind the loop still executes}} echo ' Loop over ';?