In PHP, array_key_first () gets the first key of an array however, it does not affect the internal array pointer. It was introduced in PHP 7.3.0. 



As has been noted. The parameter should be an array and it is compulsory.

Return Values

array_key_first( ) function returns the first key of the array. Moreover, if the array isn’t blank, otherwise, it’s null.



$farray = [‘a’ => 1, ‘b’ => 2, ‘c’ => 3];

$fKey = array_key_first($farray);




string(1) “a”


There are many ways to explain this functionality for versions before PHP7.3.0. Also, It can be possible to use array_key(), however, that might be not efficient. This is possible to use key() and reset() as well however it might get change the internal array pointer. A perfect solution which doesn’t change the internal array pointer is mentioned below:


if (!function_exists(‘array_key_first’)) {

    function array_key_first(array $arr) {

        foreach($arr as $key => $unused) {

            return $key;


        return NULL;




To know about the latest updates of PHP you can also visit here :

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Dix Breves Rencontres Ebook Gratuit

Pour votre bien-être et pour arriver à vos fins, rencontres gratuites – – il est indispensable de…