Home > Backend Development > PHP Tutorial > Detailed explanation of PHP array processing using three functions such as foreach, list, and each_PHP tutorial

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:40:44
Original
1097 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...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template