首页 > php教程 > php手册 > PHP 数组处理使用foreach、list、each等三个函数详解

PHP 数组处理使用foreach、list、each等三个函数详解

WBOY
发布: 2016-06-13 10:39:35
原创
1348 人浏览过

本文介绍PHP中遍历数组的foreach、list、each三个函数的使用方法:

方法1:foreach
$sports = array(
football => good,
swimming => very well,
running => not good);
foreach ($sports as $key => $value) {
echo $key.": ".$value."
";
?>

输出结果:
football: good
swimming: very well
running: not good

方法2:each
$sports = array(
football => good,
swimming => very well,
running => not good);
while ($elem = each($sports)) {
echo $elem[key].": ".$elem[value]."
";
?>

方法3:list & each
$sports = array(
football => good,
swimming => very well,
running => not good);
while (list($key, $value) = each($sports)) {
echo $key.": ".$value."
";
?>

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板