PHP Tutorial - 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

ParameterIs RequiredDescription
arrayRequired.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.