Home > Backend Development > PHP Tutorial > Detailed explanation of how to use array_key_exists() function example in PHP

Detailed explanation of how to use array_key_exists() function example in PHP

伊谢尔伦
Release: 2023-03-12 07:42:01
Original
1544 people have browsed it

array_key_exists() Definition and usage

array_key_exists() Function Determine whether a certain array exists The specified key, if the key exists, returns true, otherwise returns false.

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

Example 1

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


Output:

Key exists!
Example 2

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


Output:

Key does not exist!
Example 2

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


Output:

Key exists!

The above is the detailed content of Detailed explanation of how to use array_key_exists() function example in PHP. For more information, please follow other related articles on the PHP Chinese website!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template