Blogger Information
Blog 23
fans 0
comment 0
visits 18966
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
演绎PHP 和 JavaScript 遍历数组
手机用户1617360551
Original
645 people have browsed it

演绎PHP数组遍历

通过用php foreach的模版语法对 数组进行遍历

  1. <ol>
  2. <!-- 用PHP foreach 演绎数组遍历 -->
  3. <!-- 这里用PHP模范语法, : 相当于"{ " , endforeach 相当于 "}" -->
  4. <?php foreach ($cars as $car): ?>
  5. <li style="color:#ccc">
  6. <a href=""><?php echo $car ?>
  7. </a> </li>
  8. <?php endforeach ?>
  9. </ol>

用JS for循环对数组进行遍历

  1. <script>
  2. let cars= ['2020款 35 TFSI 时尚动感型','2021款 55 TFSI quattro 尊享致雅型',
  3. '2018款 典藏版 40 TFSI 进取版','奥迪A7 2021款 40 TFSI 豪华型','奥迪R8 2021款 V10 Coupe performance',
  4. '奥迪RS7 2021款 V10 Coupe performance'];
  5. for(let i = 0; i < cars.length ; i ++){
  6. alert(cars[i]);
  7. }
  8. </script>
  9. <?php

$cars = [‘2020款 35 TFSI 时尚动感型’,’2021款 55 TFSI quattro 尊享致雅型’,
‘2018款 典藏版 40 TFSI 进取版’,’奥迪A7 2021款 40 TFSI 豪华型’,’奥迪R8 2021款 V10 Coupe performance’,
‘奥迪RS7 2021款 V10 Coupe performance’];

  1. ?>
  2. ##代码全文
  3. <!DOCTYPE html>
  4. <html lang="en">
  5. <head>
  6. <meta charset="UTF-8">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  9. <title>Audi奥迪各系列车型</title>
  10. <style>
  11. /* 去掉链接的下划线 */
  12. ol a{
  13. text-decoration:none;
  14. }
  15. /* 加点鼠标悬停样式 */
  16. ol a:hover{
  17. color:aqua;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <h3>一汽-大众 奥迪Audi 部分车型详情</h3>
  23. <ol>
  24. <!-- PHP foreach 演绎数组遍历 -->
  25. <!-- 这里用PHP模范语法, : 相当于"{ " , endforeach 相当于 "}" -->
  26. <?php foreach ($cars as $car): ?>
  27. <li style="color:#ccc">
  28. <a href=""><?php echo $car ?>
  29. </a> </li>
  30. <?php endforeach ?>
  31. </ol>
  32. <script>
  33. let cars= ['2020款 35 TFSI 时尚动感型','2021款 55 TFSI quattro 尊享致雅型',
  34. '2018款 典藏版 40 TFSI 进取版','奥迪A7 2021款 40 TFSI 豪华型','奥迪R8 2021款 V10 Coupe performance',
  35. '奥迪RS7 2021款 V10 Coupe performance'];
  36. for(let i = 0; i < cars.length ; i ++){
  37. alert(cars[i]);
  38. }
  39. </script>
  40. </body>
  41. </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