[PHP] 纯文本查看 复制代码 <?php
$array = array("one"=>"a","two"=>"b","three"=>"c","five"=>"d");
echo "<pre>";
// For负责循环
$count = count($array);
for ($i = 0; $i < $count; $i++){
// each负责输出,输出的值为单个元素的属性集
// 每次循环each都会自动移向下一个元素
$arr = each($array);
// 输出的属性性包括4个元素,分别为键值的两种表现形式
print_r($arr);
}
// 如果each下移到最后一个元素,再调用each则会返回false
// 因此用while循环更为简单
while($b = each($array)){
print_r($b);
} 结果输出:
[HTML] 纯文本查看 复制代码 Array
(
[1] => a
[value] => a
[0] => one
[key] => one
)
Array
(
[1] => b
[value] => b
[0] => two
[key] => two
)
Array
(
[1] => c
[value] => c
[0] => three
[key] => three
)
Array
(
[1] => d
[value] => d
[0] => five
[key] => five
)
|