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:
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!