PHP » Arrays » key()

Syntax:
mixed key(array array)
array
An associative array.

Returns the key for the current element.

This function is similar to current(), but returns the key for the current element instead of the element itself.

Examples

Code:
<?php

$array1 = array(
   "un" => "one",
   "deux" => "two",
   "trois" => "three");

while ($key = key($array1)) {
   print "$key ";
   next($array1);
}

?>
Output:
un deux trois
Explanation:

The array in the example contains translations from French to English. All the French words are printed.

See Also: