# `array_key_first()` and `array_key_last()`

> Section in “New and Extended Functionality › Arrays” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/arrays/array_key_first-and-array_key_last/>

The `array_key_first()` and `array_key_last()` functions were introduced in PHP 7.3 for retrieving the first and last key of an array, respectively:

``` php
$array = ['a' => 1, 'b' => 2, 'c' => 3];

var_dump(array_key_first($array));
var_dump(array_key_last($array));
```

Executing the code shown above will print the output shown below:

    string(1) "a"
    string(1) "c"

---

Previous: [array_push() and array_unshift()](https://php7explained.com/new-and-extended-functionality/arrays/array_push-and-array_unshift/index.html.md) | Next: [Spread Operator in Array Expressions](https://php7explained.com/new-and-extended-functionality/arrays/spread-operator-in-array-expressions/index.html.md)
