温馨提示×

php array_key_exists能检查对象吗

PHP
小樊
101
2024-11-23 22:29:32
栏目: 编程语言

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 用于检查对象 MyClassproperties 数组中是否存在键名 'property1'

0