Home >>PHP Array Functions >PHP key() Function
PHP key() function is used to get the index of the element of a given input array to which the internal pointer is currently pointing. It accepts only a single parameter $array that is the given input array. It returns the index of current element of the given array as output and NULL if the input array is empty
Syntax:key($array);
Parameter | Description |
---|---|
array | array This is a required parameter. This parameter defines the array to use. |
<html> <body> <?php $x=array("A","B","C","D"); echo "The key from the current position is: ".key($x); ?> </body> </html>
<html> <body> <?php $x=array("A","B","C","D"); next($x); next($x); echo "The key from the current position is: ".key($x); ?> </body> </html>