PHP key() Function
Definition
The key() function returns the element key from the current internal pointer position.
Syntax
PHP key() Function has the following syntax.
key(array)
Parameter
Parameter | Is Required | Description |
---|---|---|
array | Required. | Array to use |
Return
This function returns FALSE on error.
Example 1
Return the element key from the current internal pointer position:
<?php
$people=array("A","B","C","D");
echo "The key from the current position is: " . key($people);
?>
The code above generates the following result.