array_last()
array_last() — Gets the last value of an array.
Built-in function of PHP 8.5. The manual lists it as available in PHP 8 >= 8.5.0. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
array_last(array $array): mixed
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $array | array | An array. |
Return value
Returns the last value of array if the array is not empty; null otherwise.
Example
A runnable snippet:
$array = [1 => 'a', 0 => 'b', 3 => 'c', 2 => 'd']; $lastValue = array_last($array); var_dump($lastValue);
Output:
string(1) "d"
See also
array_key_last(), array_first()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page array_last() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.