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

php中(foreach)用法介绍

WBOY
Release: 2016-06-13 08:52:20
Original
816 people have browsed it

php中(foreach)用法介绍

foreach ($array as $key => $value)

 

foreach    仅能用于数组,每次循环中,当前单元的键名也会在每次循环中被赋给变量    $key。当前单元的值被赋给 $value    并且数组内部的指针向前移一步。

 

 

$arr=array(0=>"你好",1=>"世界",2=>"朋友");

//var_dump($arr);

foreach ($arr as $key=>$vol){

echo "这个是键值对".$key."的结果----".$vol."
";

}

 

?>

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