array_key_last

Gets the last key of an array

Syntax

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

Parameters

array

An array.

Return

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

Examples

1

<?

$array = array("a", "b", "c");

$return = array_key_last($array);

var_export($return);

?>
2

2

<?

$array = array("key1" => "a", "key2" => "b", "key3" => "c");

$return = array_key_last($array);

var_export($return);

?>
'key3'

3

<?

$array = array();

$return = array_key_last($array);

var_export($return);

?>
NULL

Internal

array_key_first

External

PHP

Home Menu