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

key = array_key_first ($input_array);
ParameterDESCRIPTION
$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

$input=array(1,2,3,4,5);
echo array_key_first($input);
Output is here
0

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]);
Output
One

read more on array_keys()



plus2net.com




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-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer