I have an array that is structured like this:
[33] => Array
(
[time] => 1285571561
[user] => test0
)
[34] => Array
(
If you have an array
$last_element = array_pop(array);
Another solution cold be:
$value = $arr[count($arr) - 1];
The above will count the amount of array values, substract 1 and then return the value.
Note: This can only be used if your array keys are numeric.
You can use end to advance the internal pointer to the end or array_slice to get an array only containing the last element:
$last = end($arr);
$last = current(array_slice($arr, -1));
try to use
end($array);
Like said Gumbo,
<?php
$fruits = array('apple', 'banana', 'cranberry');
echo end($fruits); // cranberry
?>
$last = array_slice($array, -1, 1, true);
See http://php.net/array_slice for details on what the arguments mean.
P.S. Unlike the other answers, this one actually does what you want. :-)