批改状态:合格
老师批语:
// js中变量需要先声明才能使用let fruits = ['apple','banana','orange'];// 1. js for 遍历数组for (let index = 0; index < fruits.length; index++) {alert(fruits[index]);}// 2. js forEachfruits.forEach(fruit=>console.log(fruit));
//php变量不需要声明可以直接使用$fruits = ['apple','banana','orange'];// 1. for 遍历数组for ($i=0; $i < count($fruits) ; $i++) {echo $fruits[$i].'<br>'; //"."为 php 的连接符}// 2. foreach遍历数组foreach($fruits as $k =>$fruit){echo $k. '=>' .$fruit.'<br>';}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号