例
输出阵列中的电流,下一个和前一个元素的值:
<?php
$people = array("Peter", "Joe" , "Glenn" , "Cleveland");
echo current($people) . "<br>";
echo next($people) . "<br>";
echo prev($people);
?>
运行示例» 定义和用法
的prev()函数将内部指针移动到,并输出,所述数组中的前一个元素。
相关方法:
- next() -内部指针阵列中移动到,并输出下一个元素
- current() -在一个数组返回当前元素的值
- end() -内部指针移动到,并输出最后的元件阵列中的
- reset() -内部指针移动到所述阵列的所述第一元件
- each() -返回当前元素的键和值,和所述内部指针向前移动
句法
prev( array )
参数 | 描述 |
---|---|
array | 需要。 指定要使用的数组 |
技术细节
返回值: | 成功则返回数组中的前一个元素的值,或FALSE如果没有更多的元素 |
---|---|
PHP版本: | 4+ |
更多示例
实施例1
所有相关的方法的演示:
<?php
$people = array("Peter", "Joe" , "Glenn" , "Cleveland");
echo
current($people) . "<br>"; // The current element is Peter
echo
next($people) . "<br>"; // The next element of Peter is Joe
echo
current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>";
// The previous element of Joe is Peter
echo end($people) . "<br>"; //
The last element is Cleveland
echo prev($people) . "<br>"; // The
previous element of Cleveland is Glenn
echo current($people) . "<br>"; //
Now the current element is Glenn
echo reset($people) . "<br>"; // Moves
the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current element
(now Joe), and moves the internal pointer forward
?>
运行示例» <PHP阵列参考