定义:
foreach (array_expression as $value)------------循环时传递key
foreach (array_expression as $key => $value)-----循环时传递key和value statement 如: $arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
} $a = array(
"one" => 1,
"two" => 2,
"three" => 3,
"seventeen" => 17
);
foreach ($a as $k => $v) {
echo "\$a[$k] => $v.\n";
}
----------------------------------------------------------------扩展-------------------------------------------------------
<?php
$arr = array("one", "two", "three");
reset($arr);
while (list(, $value) = each($arr)) {
echo "Value: $value<br>\n";
}--------------------------------------------------------each循环数组并将每一个数组传递给list foreach ($arr as $value) {
echo "Value: $value<br />\n";
}-------------------------------------------------------输出的结果等同上面while的结果
?>