Blogger Information
Blog 5
fans 0
comment 0
visits 2030
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0802-演绎php遍历数组与js遍历数组的区别
马勇*JackMa
Original
374 people have browsed it
php foreach代码片段
  1. <?php
  2. $arr = [
  3. [
  4. 'id'=>1,
  5. 'title'=>'河南暴雨致302人遇难50人失踪'
  6. ],
  7. [
  8. 'id'=>2,
  9. 'title'=>'国产疫苗对Delta有用吗?钟南山回应'
  10. ],
  11. [
  12. 'id'=>3,
  13. 'title'=>'#郎平回应不再执教#'
  14. ]
  15. ];
  16. ?>
  17. <ul>
  18. <?php foreach($arr as $item): ?>
  19. <li style="display:flex;align-items:center">
  20. <span style="margin-right: 5px;"><?php echo $item['id'] ?></span>
  21. <a href=""><?php echo $item['title'] ?>
  22. </a>
  23. </li>
  24. <?php endforeach ?>
  25. </ul>

js forEach代码片段

  1. <script>
  2. const arr = [{
  3. id: 1,
  4. title: '河南暴雨致302人遇难50人失踪'
  5. }, {
  6. id: 2,
  7. title: '国产疫苗对Delta有用吗?钟南山回应'
  8. }, {
  9. id: 3,
  10. title: '#郎平回应不再执教#'
  11. }];
  12. arr.forEach(item => {
  13. console.log(`${item.id} ${item.title}`);
  14. })
  15. </script>
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