PHP array_key_exists() 函数

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

array_key_exists() 是 PHP 的一个内置函数。array_key_exists() 函数检查数组中是否存在指定的键,如果键存在则返回 true,如果键不存在则返回 false。该函数在 PHP 4.0.7 中引入。

语法

参数描述必需
指定键。必需
数组指定一个数组。必需

返回值

如果键存在,array_key_exists() 函数返回 true,如果键不存在,则返回 false。

示例 1

输出

Key does not exist!

示例 2

输出

Key exists!

示例 3

输出

Found

示例 4

输出

Key exists!