php中foreach循环遍历数组
php中foreach循环遍历数组语法:
//语法一
foreach(数组 as 值){
}
//语法二
foreach(数组 as 键=>值){
}案例代码:
<?php
$stu=['tom','berry','ketty'];
foreach($stu as $v){
echo $v,'<br>';
}
/**
tom
berry
ketty
*/
echo '<hr>';
-----------------------------------------------------------
foreach($stu as $k=>$v){
echo "{$k}:{$v}<br>";
}
/**
0:tom
1:berry
2:ketty
*/
页:
[1]