array_key_first()

array_key_first() is a native PHP function that returns the first key of an array, or null if the array is empty.

This function does not modify the internal pointer of the array, unlike using reset() and key().

<?php

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

    $key = array_key_first($array);
    // 'a'

?>

Documentation

Related : Array, [], array_search

Added in PHP 8.1