Blogger Information
Blog 43
fans 4
comment 0
visits 19293
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php分支与循环/模板用法
汇享科技
Original
341 people have browsed it

分支判断

02910-enkma4y0i6b.png

  1. // '单分支';
  2. $age = 17;
  3. if($age<18){
  4. echo '未成年';
  5. };
  6. echo '<hr>';
  7. $age = 20;
  8. //双分支
  9. if($age<18){
  10. echo '未成年';
  11. }else{
  12. echo '成年啦';
  13. }
  14. echo '<hr>';
  15. //多分支
  16. $age = 50;
  17. if($age<18){
  18. echo '未成年';
  19. }elseif($age<40){
  20. echo '成年人';
  21. }else{
  22. echo '老年人';
  23. }
  24. echo '<hr>';
  25. //语法糖
  26. //双分支语法糖 三元运算符
  27. echo $age<18 ? '未成年' : '成年了';
  28. echo '<hr>';
  29. //多分支语法糖switch
  30. $age = 70;
  31. switch(true){
  32. case $age>18 && $age<=30:
  33. echo '年轻人';
  34. break;
  35. case $age>30 && $age<=60:
  36. echo '中年人';
  37. break;
  38. case $age>60:
  39. echo '老年人';
  40. break;
  41. default:
  42. echo '未成年';
  43. };

循环输出模板

99292-ktpade8nb4i.png

  1. $shuju =[
  2. ['id'=>1,'name'=>'安邦','age'=>18,'order'=>1, 'score'=>59 ],
  3. ['id'=>2,'name'=>'安福','age'=>18,'order'=>2, 'score'=>42 ],
  4. ['id'=>3,'name'=>'安歌','age'=>18,'order'=>3, 'score'=>61 ],
  5. ['id'=>4,'name'=>'安国','age'=>18,'order'=>4, 'score'=>73 ],
  6. ['id'=>5,'name'=>'安和','age'=>18,'order'=>5, 'score'=>89 ],
  7. ['id'=>6,'name'=>'安康','age'=>18,'order'=>6, 'score'=>46 ],
  8. ['id'=>7,'name'=>'安澜','age'=>18,'order'=>7, 'score'=>65 ],
  9. ['id'=>8,'name'=>'安民','age'=>18,'order'=>8, 'score'=>62 ],
  10. ['id'=>9,'name'=>'安宁','age'=>18,'order'=>9, 'score'=>52 ],
  11. ['id'=>10,'name'=>'安平','age'=>18,'order'=>10,'score'=>55],
  12. ['id'=>11,'name'=>'安然','age'=>18,'order'=>11,'score'=>88],
  13. ['id'=>12,'name'=>'安顺','age'=>18,'order'=>12,'score'=>60]
  14. ];
  1. <body>
  2. <table>
  3. <thead>
  4. <tr>
  5. <th>ID</th>
  6. <th>姓名</th>
  7. <th>年龄</th>
  8. <th>学号</th>
  9. <th>成绩</th>
  10. </tr>
  11. </thead>
  12. <tbody>
  13. <?php foreach($shuju as $v) : ?>
  14. <tr>
  15. <?php if($v['score']>=60):?>
  16. <td><?php echo $v['id']?></td>
  17. <td><?php echo $v['name']?></td>
  18. <td><?php echo $v['age']?></td>
  19. <td><?php echo $v['order']?></td>
  20. <td><?php echo $v['score']?></td>
  21. <?php endif?>
  22. </tr>
  23. <?php endforeach ?>
  24. </tbody>
  25. </table>
  26. </body>
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