array_key_exists
函数用于检查数组中是否存在指定的键名
以下是一个示例:
class MyClass {
public $properties = array(
'property1' => 'value1',
'property2' => 'value2',
);
}
$obj = new MyClass();
$key = 'property1';
if (array_key_exists($key, $obj->properties)) {
echo "The key '{$key}' exists in the object's properties array.";
} else {
echo "The key '{$key}' does not exist in the object's properties array.";
}
在这个例子中,array_key_exists
用于检查对象 MyClass
的 properties
数组中是否存在键名 'property1'
。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:php array_key_exists能检查多维数组吗