Example 1 — Get the Last Key
Read the last key of an associative array.
<?php
$scores = ["ana" => 90, "bob" => 80, "cara" => 70];
echo array_key_last($scores), PHP_EOL; How It Works
- Create an associative array. The last key added is
cara. - Call array_key_last(). It looks at the end of the array.
- Print the result. The output is the key, not the value
70. - The array stays the same. No pointer is moved.

