Blogger Information
Blog 11
fans 0
comment 0
visits 10142
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演绎php遍历数组与js遍历数组的区别
小杂鱼
Original
470 people have browsed it

php遍历数组与js遍历数组的实例

  1. <?php
  2. $items = ['苹果','香蕉','水蜜桃','梨子'];
  3. ?>
  4. <ol>
  5. <?php foreach( $items as $item ):?>
  6. <li>
  7. <?php echo $item ?>
  8. </li>
  9. <?php endforeach?>
  10. </ol>

简写方法

  1. <?
  2. $items = ['苹果','香蕉','水蜜桃','梨子'];
  3. ?>
  4. <ol>
  5. <?foreach( $items as $item ):?>
  6. <li>
  7. <? echo $item ?>
  8. </li>
  9. <?endforeach?>
  10. </ol>
  1. <ol id="list"></ol>
  2. <script type="text/javascript">
  3. let items = ['苹果1','香蕉1','水蜜桃1','梨子1'];
  4. let Li= document.getElementById('list');
  5. for (let i = 0; i < items.length; i++) {
  6. var LI = document.createElement('li')
  7. LI.innerHTML = items[i];
  8. Li.appendChild(LI)
  9. }
  10. </script>
PHP Javascript
区别 使用模板语法直接嵌入HTML 需要DOM操作
注意点 注意起始与结束 作用域
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