Definition
The end() function sets the internal pointer of an array to its last element, and returns its value.
The end()
function is commonly used along with the following functions:
-
current()
– Returns the value of the current element in an array. -
next()
– Moves the internal pointer of an array to the next element, and returns its value. -
prev()
– Moves the internal pointer of an array to the previous element, and returns its value. -
reset()
– Set the internal pointer of an array to its first element, and returns its value. -
key()
– Returns the key of the current element in an array.
Syntax
end(array)
Parameters
Parameter | Description |
---|---|
array |
Required. Specifies the array to use. |
Example
<?php
// Example 1
$cities = array("New York", "Salt Lake", "Tokyo");
echo current($cities) . "<br>";
echo end($cities) . "<br>";
// Examples in conjuction with other related functions
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28);
echo current($ages) . "<br>";
echo next($ages) . "<br>";
echo current($ages) . "<br>";
echo prev($ages) . "<br>";
echo end($ages) . "<br>";
echo prev($ages) . "<br>";
echo current($ages) . "<br>";
echo reset($ages) . "<br>";
echo next($ages) . "<br>";