1. for的遍历数组
1) for in javascript
<body>
<script src=""></script>
<script type="text/javascript">
let news = [‘asia new’,’europe news’,’america news’];
for (let index = 0; index < news.length; index++) {
alert(news[index]);
}
</script>
</body>
#### 2) forEach in javascript
<body>
<h2><?echo=’News’?></h2>
<ol>
<li><a href=""<?echo 'asia news'?></a></li>
<li><a href=""<?echo 'europe news'?></a></li>
<li><a href=""<?echo 'america news'?></a></li>
</ol>
<script src=""></script>
<script type="text/javascript">
let news = [‘asia news’,’europe news’,’america news’];
news.forEach(news=>console.log(news));
</script>
</body>
3) for in php
<?php
$news = [‘asia news’,’europe news’,’america news’];
for ($i=0; $i < count($news) ; $i++) {
echo $news[$i]. ‘<br>‘;
}
?>
效果:
3) foreach in php
<?php
$news = [‘asia news’,’europe news’,’america news’];
foreach($news as $news)
{
echo $news.’<br>‘;
}
?>
效果跟上面是一样的