In PHP, you can use the "array_key_exists()" function to determine whether the specified key exists. The function of this function is to check whether the specified key name exists in an array; the syntax is "array_key_exists(key name) , array)", returns true if it exists, otherwise returns false.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use " array_key_exists()" function to determine whether the specified key exists.
array_key_exists() function checks whether the specified key exists in an array. If the key exists, it returns true. If the key does not exist, it returns false.
Syntax:
array_key_exists($key,$array)
$key
: Required. Specifies the key name.
$array
: Required. Specifies an array.
Example: Check if the key "Toyota" exists in the array
<?php header("Content-type:text/html;charset=utf-8"); $a=array("Volvo"=>"XC90","BMW"=>"X5"); if (array_key_exists("Toyota",$a)) { echo "指定键存在"; } else { echo "指定键不存在"; } ?>
Tip: Remember, If you omit the keys when specifying an array, integer keys will be generated starting from 0 and increasing by 1.
Recommended learning: "PHP Video Tutorial", "PHP ARRAY"
The above is the detailed content of How to determine whether the specified key exists in PHP. For more information, please follow other related articles on the PHP Chinese website!