PHP 数组处理使用foreach、list、each等三个函数详解
来源:未知 责任编辑:智问网络 发表时间:2013-11-10 20:11 点击:次
本文介绍PHP中遍历数组的foreach、list、each三个函数的使用方法:
方法1:foreach
<?php
$sports = array(
football => good,
swimming => very well,
running => not good);
foreach ($sports as $key => $value) {
echo $key.": ".$value."<br />";
?>
输出结果:
football: good
swimming: very well
running: not good
方法2:each
<?php
$sports = array(
football => good,
swimming => very well,
running => not good);
while ($elem = each($sports)) {
echo $elem[key].": ".$elem[value]."<br />";
?>
方法3:list & each
<?php
$sports = array(
football => good,
swimming => very well,
running => not good);
while (list($key, $value) = each($sports)) {
echo $key.": ".$value."<br />";
?>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>