I l@ve RuBoard Previous Section Next Section

prev

mixed prev(array array) 

Moves the internal array pointer to the previous element and returns that element's value.

Returns:

Contents of the previous element in the array; FALSE when there are no more elements

Description:

This function moves the internal array pointer to the previous element of array and returns that element's value. This can be useful with current() and next() to traverse an array; however, this is dangerous. The reason is that prev() returns the value of the element found; if this evaluates to FALSE, there is no way to tell whether you've actually hit the beginning of the array being traversed, or the previous element simply has a value of FALSE.

Version:

PHP 3, PHP 4

See also:

end() 
key() 
current() 
next() 
reset() 

Example:

Move the internal array pointer back one element
$my_array = array('a', 'b', 'c', 'd', 'e'); 
echo end($my_array); 
for ($i = 0; $i <= count($my_array); $i++) {
   echo "\n" . prev($my_array); 
} 

Output: 
e 
d 
c 
b 
a 
    I l@ve RuBoard Previous Section Next Section