PHP key() 函数

2025 年 1 月 6 日 | 阅读 1 分钟

key() 函数从当前内部指针位置返回元素键。该函数在 4.0 版本中引入。

语法

参数

参数描述必需
数组指定要使用的数组。必需

返回值

key() 返回当前内部指针指向的数组元素的键。

示例 1

输出

The key from the current position is: 0

示例 2

输出

Current position Key is : Subject1

示例 3

输出

Current position Key is :tata

示例 4

输出

The key from the current position is: 0