Home > php教程 > php手册 > php数组函数序列之array_key_exists()

php数组函数序列之array_key_exists()

WBOY
Release: 2016-06-06 20:39:07
Original
1008 people have browsed it

array_key_exists() 函数判断某个数组中是否存在指定的 key,如果该 key 存在,则返回 true,否则返回 false

array_key_exists() 定义和用法
array_key_exists() 函数判断某个数组中是否存在指定的 key,如果该 key 存在,则返回 true,否则返回 false。

语法
array_key_exists(key,array)
参数 描述
key 必需。规定键名。
array 必需。规定输入的数组。

例子 1
代码如下:
$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("a",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>

输出:

Key exists!
例子 2
代码如下:
$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("c",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>

输出:

Key does not exist!
例子 2
代码如下:
$a=array("Dog",Cat");
if (array_key_exists(0,$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>

输出:

Key exists!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template