Home >Backend Development >PHP Tutorial >php list & each example code_PHP tutorial

php list & each example code_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:02:12886browse

PHP list & each example code definition and usage each() function generates an array consisting of the key name and key value of the element pointed to by the current internal pointer of the array, and moves the internal pointer forward ​

php tutorial list & each example code
Definition and Usage
The each() function generates an array consisting of the key name and key value of the element currently pointed to by the internal pointer of the array, and moves the internal pointer forward.

The returned array includes four elements: key names 0, 1, key and value. Cells 0 and key contain the key names of the array cells, and 1 and value contain the data.

If the internal pointer exceeds the range of the array, this function will return false.

*/
$sports = array(
'football' => 'good',
'swimming' => 'very www.bkjia.com',
'running' => 'not good');

while (list($key,$value) = each($sports))
{
echo $key.": ".$value."
";
}
/*


Definition and Usage
The list() function assigns values ​​to a set of variables using elements in an array.

Note that, like array(), list() is actually a language construct, not a function.

*/

$sports = array(
'football' => 'good',
'swimming' => 'very well',
'running' => 'not www.bkjia.com');
while ($elem = each($sports)) {
echo $elem['key'].": ".$elem['value']."
";
}


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445394.htmlTechArticlephp list each example code definition and usage each() function generates an element pointed to by the current internal pointer of the array An array composed of key names and key values, and moves the internal pointer forward PHP teaches...
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