PHP key() function returns the key name of the element currently pointed to by the internal pointer of the array. Its syntax is key(array). The parameter array is required and refers to the array to be used.
#How to use the php key function?
php key() function syntax
Function: Returns the key name of the element currently pointed to by the internal pointer of the array.
Syntax:
key(array)
Parameters:
array Required. Specifies the array to use.
Description:
Returns the key name of the element currently pointed to by the internal pointer of the array. If an error occurs, the function returns FALSE.
php key() function usage example 1
<?php $people = array("西门", "灭绝", "无忌"); echo "键的当前位置是:" . key($people); ?>
Output:
键的当前位置是:0
php key() function usage example 2
<?php $arr = array("西门", "灭绝", "无忌"); $arr2 = next($arr); //指向下一个元素 灭绝 echo key($arr); //输出灭绝的 key值 ?>
Output:
1
This article is an introduction to the PHP key function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use php key function. For more information, please follow other related articles on the PHP Chinese website!