array_key_exists函数用于检查数组中是否存在指定的键名
array_key_exists函数用于检查数组中是否存在指定的键名。其语法如下:
array_key_exists($key,$array)
其中,$key为要检查的键名,$array为要检查的数组。
示例:
$colors=array("red"=>"apple","yellow"=>"banana","green"=>"pear");
if(array_key_exists("red",$colors)){
echo"Redcolorexistsinthearray";
}else{
echo"Redcolordoesnotexistinthearray";
}
在上面的示例中,我们首先创建了一个包含颜色和水果的关联数组$colors。然后使用array_key_exists函数检查数组中是否存在键名为"red",如果存在则输出"Redcolorexistsinthearray",否则输出"Redcolordoesnotexistinthearray"。
版权声明
本文仅代表作者观点,不代表博信信息网立场。