Blogger Information
Blog 41
fans 2
comment 0
visits 29342
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js中的循环和php循环的区别
月光下,遗忘黑暗
Original
725 people have browsed it

1.代码块

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Document</title>
  9. </head>
  10. <body>
  11. <script>
  12. let arr = [1,3,4];
  13. for (let i=0;i<arr.length;i++) {
  14. console.log(arr[i]);
  15. }
  16. arr.forEach((item,index)=>console.log(item,index));
  17. </script>
  18. </body>
  19. </html>
  20. <?php
  21. $arr = [1,3,4];
  22. $count = count($arr);
  23. for ($i=0;$i<$count;$i++) {
  24. var_dump($arr[$i]);
  25. }
  26. foreach ($arr as $k => $v) {
  27. var_dump([$k=>$v]);
  28. }
  29. //结论
  30. //for => for,forEach => foreach

效果

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