Home  >  Article  >  Backend Development  >  PHP array function sequence array_key_exists() - Find whether the array key exists_PHP tutorial

PHP array function sequence array_key_exists() - Find whether the array key exists_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:23:31990browse

array_key_exists() Definition and usage
array_key_exists() function determines whether the specified key exists in an array. If the key exists, it returns true, otherwise it returns false.

Syntax
array_key_exists(key,array)
Parameter Description
key Required. Specifies the key name.
array required. Specifies the input array.

Example 1

Copy code The code is as follows:

$a= array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("a",$a))
{
echo "Key exists! ";
}
else
{
echo "Key does not exist!";
}
?>

Output:

Key exists!
Example 2
Copy code The code is as follows:

$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("c",$a))
{
echo " Key exists!";
}
else
{
echo "Key does not exist!";
}
?>

Output:

Key does not exist!
Example 2
Copy code The code is as follows:

< ?php
$a=array("Dog",Cat");
if (array_key_exists(0,$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>

Output:

Key exists!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324493.htmlTechArticlearray_key_exists() Definition and usage array_key_exists() function determines whether the specified key exists in an array. If the key If exists, return true, otherwise return false. Syntax ar...
Statement:
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