admin 发表于 2022-11-23 17:26:43

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]
查看完整版本: php中foreach循环遍历数组