Detailed explanation of PHP array processing using three functions such as foreach, list, and each_PHP tutorial

WBOY
Release: 2016-07-13 17:40:44
Original
976 people have browsed it

This article introduces how to use the three functions foreach, list, and each for traversing arrays in PHP:

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

Output result:
football: good
swimming: very well
running: not good

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

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486188.htmlTechArticleThis article introduces how to use the three functions of foreach, list, and each to traverse arrays in PHP: Method 1: foreach? php $sports = array( football = good, swimming = very well, running = not...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!