溫馨提示×

php array_key_exists能檢查對象嗎

PHP
小樊
90
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
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女