Blogger Information
Blog 14
fans 0
comment 0
visits 9504
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP遍历数组与Javascript遍历数组
Mr.Ran
Original
632 people have browsed it

PHP代码

  1. <ul>
  2. <?php
  3. $cars = ['宝马x1','宝马x2','宝马x3','宝马x4'];
  4. foreach($cars as $car){?>
  5. <li><? echo $car?></li>
  6. <?}?>
  7. </ul>

JavaScript代码

  1. <ul>
  2. <script>
  3. var cars = ['宝马x1','宝马x2','宝马x3','宝马x4'];
  4. for (let i = 0; i < cars.length; i++) {
  5. document.write("<li>"+cars[i]+"</li>");
  6. }
  7. </script>
  8. </ul>

两者区别在于运行环境不同。PHP在服务端执行,JS在客户端执行。

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:foreach {}中{ 可以用 : 代替
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