Home >Backend Development >PHP Tutorial >Detailed explanation of the steps for searching array key names using the array_key_exists() function

Detailed explanation of the steps for searching array key names using the array_key_exists() function

php中世界最好的语言
php中世界最好的语言Original
2018-05-21 10:03:342778browse

This time I bring you array_key_exists()FunctionSearch Detailed explanation of the steps of array key name, array_key_exists() function to search array key name What are the precautions? The following is a practical case, let’s take a look.

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, php array function array_key_exists().

<?php 
$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, PHP array function array_key_exists().

<?php 
$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 3, PHP array function array_key_exists().

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

Output:
Key exists!

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps to create scheduled tasks through the yii framework through console commands

PHP7 uses lib based on functions Library case code analysis

The above is the detailed content of Detailed explanation of the steps for searching array key names using the array_key_exists() function. For more information, please follow other related articles on the PHP Chinese website!

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