array_key_last

(PHP 7 >= 7.3.0)

array_key_lastGets the last key of an array

Description

mixed array_key_last ( array $array )

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

Parameters

array

An array.

Return Values

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

See Also

  • array_key_first() - Gets the first key of an array
  • end() - Set the internal pointer of an array to its last element
add a note add a note

User Contributed Notes 1 note

up
0
Anyvie at devlibre dot fr
2 months ago
For PHP <= 7.3.0 :

if (! function_exists("array_key_last")) {
    function array_key_last($array) {
        if (!is_array($array) || empty($array)) {
            return NULL;
        }
       
        return array_keys($array)[count($array)-1];
    }
}
To Top