downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

range> <pos
[edit] Last updated: Fri, 25 May 2012

view this page in

prev

(PHP 4, PHP 5)

prev将数组的内部指针倒回一位

说明

mixed prev ( array &$array )

返回数组内部指针指向的前一个单元的值,或当没有更多单元时返回 FALSE

Warning

如果数组包含空的单元,或者单元的值是 0 则本函数碰到这些单元也返回 FALSE。要正确遍历可能含有空单元或者单元值为 0 的数组,参见 each() 函数。

prev()next() 的行为类似,只除了它将内部指针倒回一位而不是前移一位。

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';
?>

参见 current()end()next()reset()



add a note add a note User Contributed Notes prev
soapergem at gmail dot com 29-May-2009 06:06
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 29-Sep-2007 06:19
// 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);
}

 
show source | credits | stats | sitemap | contact | advertising | mirror sites