Blogger Information
Blog 7
fans 0
comment 0
visits 12103
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php遍历数组与js遍历数组
A特权?&非凡群直播&社群裂变
Original
478 people have browsed it

效果

代码

  1. <?php
  2. $cars=['1系PHP','3系PHP','5系PHP'];
  3. $coolcars=['2系PHP','4系PHP','7系PHP'];
  4. ?>
  5. <!DOCTYPE html>
  6. <html lang="en">
  7. <head>
  8. <meta charset="UTF-8">
  9. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <title>BMW好车</title>
  12. </head>
  13. <body>
  14. <h2><? echo '宝马好车(无循环)'?></h2>
  15. <ol>
  16. <li><a href=""><? echo '1系'?></a></li>
  17. <li><a href=""><? echo '3系'?></a></li>
  18. <li><a href=""><? echo '5系'?></a></li>
  19. </ol>
  20. <h2><? echo '宝马好车(PHP foeach)'?></h2>
  21. <ol>
  22. <!--
  23. 未使用模版语法
  24. -->
  25. <? foreach($cars as $car){?>
  26. <li><a href=""><? echo $car ?></a></li>
  27. <? } ?>
  28. <!--
  29. if,while,for,forforeach,switch这些流程控制语句都有替代语法。
  30. :代替了左边的花括号{
  31. 并用endforeach代替结束时的右边的花括号} -->
  32. <? foreach($coolcars as $coolcar):?>
  33. <li><a href=""><? echo $coolcar ?></a></li>
  34. <? endforeach ?>
  35. </ol>
  36. <!-- JS for循环 演示 -->
  37. <script type="text/javascript">
  38. let cars=['1系PHP','3系PHP','5系PHP'];
  39. for (let index = 0; index < cars.length; index++)
  40. {
  41. alert(cars[index]);
  42. }
  43. </script>
  44. </body>
  45. </html>
Correcting teacher:灭绝师太灭绝师太

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