1.代码块
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
let arr = [1,3,4];
for (let i=0;i<arr.length;i++) {
console.log(arr[i]);
}
arr.forEach((item,index)=>console.log(item,index));
</script>
</body>
</html>
<?php
$arr = [1,3,4];
$count = count($arr);
for ($i=0;$i<$count;$i++) {
var_dump($arr[$i]);
}
foreach ($arr as $k => $v) {
var_dump([$k=>$v]);
}
//结论
//for => for,forEach => foreach
效果