Blogger Information
Blog 22
fans 0
comment 0
visits 15610
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php 中的for and foreach遍历数组
杰西卡妈妈
Original
704 people have browsed it

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>‘;
}
?>

效果跟上面是一样的

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