Hi Reader's,
Welcome to FindNerd, today we are going to discuss about key() function in php.
The key() function returns the index element of the current array position.
Or we can say that returns the element key from the current internal pointer position.
The key() function returns false on error.
syntax of key() function
key(array)
array is required parameter
you can take reference of bellow example:
<?php
//here define a variable of array
$data = array(
'Emp_name' => 'mac',
'Emp_age' => 35,
'Emp_dep' => 'account',
);
//here call key()
$key = key($data);
//print the $key
var_dump($key);
?>
output will come following of above example
string(8) "Emp_name"
0 Comment(s)