In this article, you will learn how to get the key to which the current internal pointer is pointing in the array. The key() method returns the key of the element to which the current pointer is pointing.
What is the syntax of the key() function in PHP?
key(array)
Parameter | Details |
---|---|
array | The array to use with the key method – Required |
Example of key() function
Example 1. Get the key of the element at the current pointer position.
<?php
$members=array("Jawad","Ahmad","Sumerina","ACS");
echo "Current pointer is pointing to the key: " . key($members);
?>