博主信息
博文 19
粉丝 1
评论 0
访问量 16411
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
PHP作业js php——for foreach
▽空城旧梦
原创
784人浏览过

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>
批改老师:天蓬老师天蓬老师

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学