PHP key() function

PHP in_array() function
PHP krsort() function

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)
ParameterDetails
arrayThe array to use with the key method – Required
PHP key method

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);
?>
PHP in_array() function
PHP krsort() function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top