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

