array_key_first(): to get the first key of an array

key = array_key_first ($input_array);
$input_arrayRequired : Input array for which first key is to be returned.
arrays_key_first() function returns the first key of the array. If the array is empty then NULL is returned.
PHP 7.3.0 Supported by PHP 7.3.0 and above

Example 1

echo array_key_first($input);
Output is here

Example 2

$input=array('One' =>'First','Two'=>'Second','Three'=>'Third','Fourth');
echo var_dump(array_key_first($input));
The output is here
string(3) "One"

Getting first key using array_keys()

$input=array('One' =>'First','Two'=>'Second','Three'=>'Third','Fourth');
echo (array_keys($input)[0]);

read more on array_keys()

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here .

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer