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. 

Parameters

array

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.

Example 

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

$fKey = array_key_first($farray);

var_dump($fKey);

?>

Output

string(1) “a”

Tip

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 :

  • DROPDOWN MENU NOT BEING DISPLAYED ON THE FIRST CLICK AFTER BEING CREATED DYNAMICALLY
  • HOW TO COPY-PASTE HTML TO SUMMER NOTE
  • WHY DOES NOT THE ANIMATION SPEED PARAMETER TAKE MY VARIABLE JQUERY
  • CANNOT ABLE TO FETCH DATA FROM AJAX TO THE PHP PAGE
  • SET DATE AND TIME IN JQUERY DATE AND TIME PICKER WITH SELENIUM
0
0
0
Share 0
Tweet 0
Pin it 0
0 Shares:
Share 0
Share 0
Tweet 0
Share 0
Share 0
Share 0
Share 0
Leave a Reply

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

You May Also Like
Read More

How to spam protection in WordPress

How to spam projection in WordPress? It is most used feature of Preventing WordPress comment spam which is an ongoing regular process that can be done in 2 ways

Dix Breves Rencontres Ebook Gratuit

Pour votre bien-être et pour arriver à vos fins, rencontres gratuites – https://www.paparencontres.fr/rencontres-gratuites/ – il est indispensable de…