Current Location: Home> Function Categories> key

key

Get key names from associative array
Name:key
Category:Array
Programming Language:php
One-line Description:Get the key name from the associative array.

Definition and usage

key() function returns the key name of the current pointer to the element in the array.

If an error occurs, the function returns FALSE.

This function is similar to current() , except that the result returns are different. current() function returns the value of the element, while the key() function returns the key name of the element.

Example

Return the element key name from the current internal pointer position:

 <?php
$people = array ( "Bill" , "Steve" , "Mark" , "David" ) ;
echo "The current position of the key is:" . key ( $people ) ;
?>

Try it yourself

grammar

 key ( array )
parameter describe
array Required. Specifies the array to be used.
Similar Functions
Popular Articles