首頁 > 後端開發 > php教程 > PHP 数组处理使用foreach、list、each等三个函数详解_PHP教程

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

WBOY
發布: 2016-07-13 17:40:44
原創
1030 人瀏覽過

本文介绍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."
";
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486188.htmlTechArticle本文介绍PHP中遍历数组的 foreach、list、each 三个函数的使用方法: 方法1:foreach ?php $sports = array( football = good, swimming = very well, running = not...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板