Home > php教程 > php手册 > body text

php list & each 实例代码

WBOY
Release: 2016-06-13 11:18:22
Original
1149 people have browsed it

php list & each 实例代码定义和用法each() 函数生成一个由数组当前内部指针所指向的元素的键名和键值组成的数组,并把内部指针向前移动  

php教程 list & each 实例代码
定义和用法
each() 函数生成一个由数组当前内部指针所指向的元素的键名和键值组成的数组,并把内部指针向前移动。

返回的数组中包括的四个元素:键名为 0,1,key 和 value。单元 0 和 key 包含有数组单元的键名,1 和 value 包含有数据。

如果内部指针越过了数组范围,本函数将返回 false。

 

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


定义和用法
list() 函数用数组中的元素为一组变量赋值。

注意,与 array() 类似,list() 实际上是一种语言结构,不是函数。

*/

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


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 Recommendations
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!