(PHP 4, PHP 5)
prev — 将数组的内部指针倒回一位
array
The input array.
返回数组内部指针指向的前一个单元的值,或当没有更多单元时返回 FALSE
。
Example #1 prev() 及相关函数用法示例
<?php
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport); // $mode = 'foot';
$mode = next($transport); // $mode = 'bike';
$mode = next($transport); // $mode = 'car';
$mode = prev($transport); // $mode = 'bike';
$mode = end($transport); // $mode = 'plane';
?>
soapergem at gmail dot com (2009-05-29 12:06:28)
Here's a slight revision to xmlich02's backwards iteration example. The problem with his/her example is that it will halt if any of the array elements are boolean false, while this version will not.
<?php
end($ar);
while ( !is_null($key = key($ar)) ) {
$val = current($ar);
echo "{$key} => {$val}\n";
prev($ar);
}
?>
xmlich02 at stud dot fit dot vutbr dot cz (2007-09-29 12:19:29)
// example of backward iteration
$ar = array ( 'a', 'b', 'c', 'd', 'e', 'f') ;
print_r($ar);
end($ar);
while($val = current($ar)) {
echo $val.' ';
prev($ar);
}