Definition :
In PHP Array key () function fetch the key or index of the current element in an array.
Tip: Every array has an internal pointer that points to the current element in the array. When a new array is created, the current pointer is initialized to reference the first element in the array.
Syntax
The basic syntax of the key() function is given with:
key(array);
The key()
function accepts the following parameters.
Parameter | Description |
---|---|
array | Required. Specifies the array to work on. |
Example : Below example Return the element key from the current internal pointer position.
Output : The key from the current position is: 0