是的,array_key_exists
函数可以用于检查关联数组中是否存在指定的键
<?php
$assoc_array = array(
"name" => "John",
"age" => 30,
"city" => "New York"
);
if (array_key_exists("name", $assoc_array)) {
echo "Key 'name' exists in the associative array.";
} else {
echo "Key 'name' does not exist in the associative array.";
}
?>
在这个例子中,array_key_exists
检查 $assoc_array
是否包含键 “name”。如果存在,它将输出 “Key ‘name’ exists in the associative array.”,否则输出 “Key ‘name’ does not exist in the associative array.”。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:php array_key_exists能检查多维数组吗