Home  >  Article  >  Backend Development  >  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

WBOY
WBOYOriginal
2016-07-13 17:40:44932browse

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:
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