JS
<script>
//js需要先申明变量
let arr= ["apple","banana","orange","cherry","lemon"];
for (let i=0; i<arr.length ;i++) {
console.log(arr[i]);
}
arr.forEach(arr=>console.log(arr));
</script>
- PHP
<?php
//php数组遍历
//变量不需要声明直接使用
$arrs = ["apple","banana","orange","cherry","lemon"];
for($i=0;$i<count($arrs);$i++) {
echo $arrs[$i] ."<br>";
};
echo "<hr>";
foreach($arrs as $arr) {
echo $arr;
}
?>