PHP key() Function
In this chapter you will learn:
- Definition for PHP key() Function
- Syntax for PHP key() Function
- Parameter for PHP key() Function
- Return value for PHP key() Function
- Example - Return the element key from the current internal pointer position
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
Parameter | Is Required | Description |
---|---|---|
array | Required. | 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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP krsort() Function
- Syntax for PHP krsort() Function
- Parameter for PHP krsort() Function
- Note for PHP krsort() Function
- Example - Sort an associative array in descending order, according to the key
Home » PHP Tutorial » PHP Array Functions