array_key_last()

array_key_last() — Gets the last key of an array.

Built-in function of PHP 8.5. The manual lists it as available in PHP 7 >= 7.3.0, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Get the last key of the given array without affecting the internal array pointer.

Signature

array_key_last(array $array): int|string|null

Parameters

ParameterTypeWhat it takes
$arrayarrayAn array.

Return value

Returns the last key of array if the array is not empty; null otherwise.

Example

The PHP manual ships no example for array_key_last(); the signature and the parameter table above are the contract.

See also

array_last(), array_key_first(), end()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page array_key_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.