<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> each.php </title>
<meta charset="UTF-8">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<?php
$foo = array("bob", "fred", "jussi");
$bar = each($foo);
echo '$bar 当前的内容:';
print_r($bar);
$foo = array("Robert" => "Bob", "Seppo" => "Sepi");
$bar_1 = each($foo);
echo '<br>$bar_1 当前的内容:';
print_r($bar);
//使用each 函数输出数组内容
$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');
reset($fruit); //数组指针归0
echo '<br>$fruit 数组全部元素:<br>';
while (list($key, $val) = each($fruit)) { //循环输出数组内容
echo "$key => $val<br>";
}
?>
</body>
</html>
$bar 当前的内容:Array ( [1] => bob [value] => bob [0] => 0 [key] => 0 )
$bar_1 当前的内容:Array ( [1] => bob [value] => bob [0] => 0 [key] => 0 )
$fruit 数组全部元素:
a => apple
b => banana
c => cranberry