I l@ve RuBoard Previous Section Next Section

end

mixed end(array array) 

Sets the internal array pointer to the last element of the array and returns that element's value.

Returns:

Contents of the last array element

Description:

Sets the internal array pointer to the last element of array and returns the value of that element. This can be used to quickly seek to the end of an array; for instance, if you need to iterate through an array backwards but don't want to reverse the array using something like array_reverse().

Version:

PHP 3, PHP 4

See also:

current() 
key() 
next() 
prev() 
reset() 

Example:

Iterate from the end of an array to the beginning
$my_array = array("a", "b", "c", "d", "e"); 
echo "The last element of the array is: " . end($my_array); 
   for ($i = count($my_array); $i >= 0; $i--) {
   echo "\n"; 
echo prev($my_array); 
} 

Output: 
The last element of the array is: e 
d 
c 
b 
a 
    I l@ve RuBoard Previous Section Next Section