Blogger Information
Blog 62
fans 3
comment 1
visits 29744
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php分支与循环写法
kiraseo_wwwkiraercom
Original
313 people have browsed it

php分支

代码如下

  1. <?php
  2. echo "多分支<br/>";
  3. $age = 128;
  4. if($age >=18 && $age<35){
  5. echo '可以吃糖啦!';
  6. }
  7. else if($age >=35 && $age<50){
  8. echo '建议少吃糖!';
  9. }
  10. else if($age<18 || $age >60){
  11. echo '不能吃糖!';
  12. }
  13. else{
  14. echo '不建议吃糖!';
  15. }
  16. echo '<hr/>';
  17. echo "单分支<br/>";
  18. $scores = 60;
  19. if($scores>=60){
  20. echo "您的分数{$scores},及格啦!!!";
  21. }
  22. echo '<hr/>';
  23. $scores = 55;
  24. if($scores>=60){
  25. echo "您的分数{$scores},及格啦!!!";
  26. }else{
  27. echo "您的分数{$scores},不及格,要多加强学习啦!!!";
  28. }
  29. echo '<hr/>';
  30. echo "switch写法<br/>";
  31. $age = 25;
  32. switch (true) {
  33. case $age >= 18 && $age < 30:
  34. echo "{$age}岁可以吃糖啦<br>";
  35. break;
  36. case $age >= 30 && $age < 45:
  37. echo "{$age}岁,建议少吃糖<br>";
  38. break;
  39. case $age<18 || $age >60:
  40. echo "{$age}岁,不能吃糖<br>";
  41. break;
  42. default:
  43. echo "{$age}岁,放学,我送你回家<br>";
  44. }
  45. ?>

输出结果

php循环输出与模板写法

代码如下

  1. <?php
  2. namespace _0809作业;
  3. $an_arrs =[
  4. ['id'=>1,'name'=>'安邦','age'=>18,'order'=>1, 'score'=>59 ],
  5. ['id'=>2,'name'=>'安福','age'=>18,'order'=>2, 'score'=>42 ],
  6. ['id'=>3,'name'=>'安歌','age'=>18,'order'=>3, 'score'=>61 ],
  7. ['id'=>4,'name'=>'安国','age'=>18,'order'=>4, 'score'=>73 ],
  8. ['id'=>5,'name'=>'安和','age'=>18,'order'=>5, 'score'=>89 ],
  9. ['id'=>6,'name'=>'安康','age'=>18,'order'=>6, 'score'=>46 ],
  10. ['id'=>7,'name'=>'安澜','age'=>18,'order'=>7, 'score'=>65 ],
  11. ['id'=>8,'name'=>'安民','age'=>18,'order'=>8, 'score'=>62 ],
  12. ['id'=>9,'name'=>'安宁','age'=>18,'order'=>9, 'score'=>52 ],
  13. ['id'=>10,'name'=>'安平','age'=>18,'order'=>10,'score'=>55],
  14. ['id'=>11,'name'=>'安然','age'=>18,'order'=>11,'score'=>88],
  15. ['id'=>12,'name'=>'安顺','age'=>18,'order'=>12,'score'=>60]
  16. ];
  17. ?>
  18. <!DOCTYPE html>
  19. <html lang="zh-CN">
  20. <head>
  21. <meta charset="UTF-8">
  22. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  23. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  24. <title>学生信息管理系统</title>
  25. <style>
  26. table {border-collapse: collapse;width: 360px;text-align: center;}
  27. table th,
  28. table td {border: 1px solid #000;padding: 5px;}
  29. table caption {font-size: 1.3em;}
  30. table thead {background-color: lightcyan;}
  31. </style>
  32. </head>
  33. <body>
  34. <?php
  35. ?>
  36. <table>
  37. <caption>学生成绩表</caption>
  38. <thead>
  39. <tr>
  40. <th>ID</th>
  41. <th>姓名</th>
  42. <th>年龄</th>
  43. <th>学号</th>
  44. <th>成绩</th>
  45. </tr>
  46. </thead>
  47. <tbody>
  48. <?php foreach ($an_arrs as $an) : ?>
  49. <tr>
  50. <td><?php echo $an['id']?></td>
  51. <td><?php echo $an['name']?></td>
  52. <td><?php echo $an['age']?></td>
  53. <td><?php echo $an['order']?> </td>
  54. <td><?php echo $an['score']?></td>
  55. </tr>
  56. <?php endforeach ?>
  57. </tbody>
  58. </table>
  59. </body>
  60. </html>

输出结果

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