Blogger Information
Blog 19
fans 1
comment 0
visits 12264
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP作业js php——for foreach
▽空城旧梦
Original
598 people have browsed it

js中for forEach和php中for foreach遍历

  1. <?php
  2. $nums=[1,2,3,4,5,6];
  3. $cars=["BWM","AUDI","Volvo"];
  4. for ($i=0; $i <count($nums) ; $i++) {
  5. echo $nums[$i].'<br>';
  6. }
  7. foreach($cars as $car)
  8. {
  9. echo $car.'<br>';
  10. }
  11. echo "<hr>";
  12. ?>
  13. <!DOCTYPE html>
  14. <html lang="zh-CN">
  15. <head>
  16. <meta charset="UTF-8" />
  17. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  18. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  19. <title>Document</title>
  20. </head>
  21. <body>
  22. <ul class="list">
  23. <li class="item">item1</li>
  24. <li class="item">item2</li>
  25. <li class="item">item3</li>
  26. <li class="item">item4</li>
  27. <li class="item">item5</li>
  28. </ul>
  29. <script>
  30. const arrs = document.querySelectorAll(".item");
  31. console.log(arrs);
  32. arrs.forEach((elments) => console.log(elments));
  33. for (let index = 0; index < arrs.length; index++) {
  34. const element = arrs[index];
  35. console.log(element);
  36. }
  37. </script>
  38. </body>
  39. </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