PHP key() Function

The key() function is used to get the index element of the current array position.

This function returns FALSE on error.

Returns the key of the array element that is currently being pointed to by the internal pointer

Parameter Description
array Required. Specifies the array to use

Syntax

key(array) 

Example

$people=array("James","Cooper","Samuel","Alex");
echo "key: " . key($people);

Output

key: 0

Leave a Reply

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