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; ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.