PHP key() Function

The key( ) function returns the element key from the current internal pointer position. This function was introduced in 4.0.

Syntax

Parameter

ParameterDescriptionIs compulsory
arraySpecifies the array to use.compulsory

Returns

The key( ) returns the key of the array element that is currently being pointed by the internal pointer.

Example 1

Output:

The key from the current position is: 0

Example 2

Output:

Current position Key is : Subject1

Example 3

Output:

Current position Key is :tata

Example 4

Output:

The key from the current position is: 0