Home >Backend Development >PHP Tutorial >php-Arrays function-array_key_exists-checks whether the given key name or index exists in the array_PHP tutorial
array_key_exists() checks whether the given key name or index exists in the array
【Function】
This function will return a Boolean value,
If the specified key exists in the specified array, it returns true, otherwise it returns false
At the same time, this function can also be used for objects, that is, to check whether the specified key is in the object
【Scope of use】
php4>4.1.0, php5.
【Use】
bool array_key_exists(mixed key,array search)
key/required/key name
search/required/search array
【Example】
[php]
$search_array = array('first'=>1,'second'=>4);
if(array_key_exists('first',$search_array)){
echo "The 'first' element is in the array";
}
/*
The 'first' element is in the array
*/
Excerpted from zuodefeng’s notes