PHP array_key_last()Function
Complete PHP Array Reference Manual
Examples
Get the last key of an array:
$array = ['a' => 1, 'b' => 2, 'c' => 3];
$lastKey = array_key_last($array);
echo $lastKey;
Run the above code, the output is:
c
Definition and Usage
The array_key_last() function gets the last key of an array.
Gets the last key of the specified array without affecting the internal pointer of the original array.Syntax
array_key_last ( array $array ) : mixed
| Parameter | Description |
|---|---|
| array | The array to operate on. |
Technical Details
| Return value: | Returns the last key of the array (if not empty), otherwise returns null. |
|---|---|
| PHP version: | PHP 7 >= 7.3.0, PHP 8 |
Other Extensions