Blogger Information
Blog 29
fans 1
comment 0
visits 14949
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP流程控制练习
Pharaoh
Original
571 people have browsed it
  1. <?php
  2. // 单分支
  3. $name = 'pharaoh';
  4. if ($name === 'pharaoh')
  5. {
  6. echo $name;
  7. }
  8. echo '<br>';
  9. // 双分支
  10. $num = 30;
  11. if ($num >= 30)
  12. {
  13. echo sprintf('你已经%s岁了',$num);
  14. }
  15. else {
  16. printf('你还小不能访问');
  17. }
  18. echo '<br>';
  19. // 三元运算符
  20. $num = 17;
  21. echo $num >= 30 ? sprintf('你已经%s岁了',$num) : '你还小不能访问';
  22. echo '<hr/ >';
  23. // 多分支
  24. $sex = 'male';
  25. if ($sex === 'male') {
  26. echo '你是男性';
  27. }elseif ($sex === 'female') {
  28. echo '你是女性';
  29. }else {
  30. echo '你是男是女?';
  31. }
  32. echo '<hr/>';
  33. // switch
  34. $time = 45;
  35. switch($time) {
  36. case $time <= 60 && $time !== 0:
  37. echo 'You are best!!';
  38. break;
  39. case $time >= 60 && $time <= 80:
  40. echo 'Come on!!';
  41. break;
  42. default:
  43. echo 'looser!';
  44. }

模板语法

  1. <!-- 模板语法 -->
  2. <?php foreach($arr as $values): ?>
  3. <?='<tr>' ?>
  4. <td><?=$values['name']?></td>
  5. <td><?=$values['sex']?></td>
  6. <td><?=$values['power']?></td>
  7. <?='</tr>' ?>
  8. <?php endforeach?>
  9. <?php foreach ($arr as $values): ?>
  10. <?php if($values['power'] === 0):?>
  11. <?= '<tr style="color:red">'?>
  12. <?= '<td>' . $values['name'] . '</td>'?>
  13. <?= '<td>' . $values['sex']. '</td>'?>
  14. <?= '<td>' . $values['power']. '</td>'?>
  15. <?= '</tr>'?>
  16. <?php endif?>
  17. <?php endforeach?>

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post