Home > Article > Backend Development > The difference between php array_key_exists() and isset()
This article mainly introduces relevant information about the difference between php array_key_exists() and isset(). Friends who need it can refer to it
php array_key_exists is used to check whether a key name exists in the array. Iset can also be used to detect whether a certain key name exists in an array, so what is the difference between the two? This article will explain to you some differences in the use of array_key_exists() and isset()
A basic difference is that isset() can be used for arrays and variables, while array_key_exits() can only be used for arrays.
But the main difference lies in the return value under the set conditions.
Now let’s verify this main difference.
array_key_exists()
array_key_exists() will check the existence of the key value. This function will return TRUE as long as the key value exists, even if the value is NULL.
$arr = array( "one"=>"1", "two"=>"2", "three"=>null ); array_key_exists("one", $arr); // true array_key_exists("two", $arr); // true array_key_exists("three", $arr); // true
isset()
Different from arrry_key_exitst(), isset() will check the key and value at the same time. Only when the key exists, TRUE will be returned only when the corresponding variable is not NUll.
$arr = array( "one"=>"1", "two"=>"2", "three"=>null ); isset($arr["one"]); // true isset($arr["two"]); // true isset($arr["three"]); // false
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
Detailed explanation of PHP custom image center cropping function
PHP recursively implements folder copying, deletion, viewing size, etc.
What are the ways to implement multi-dimensional array sorting algorithm in PHP
The above is the detailed content of The difference between php array_key_exists() and isset(). For more information, please follow other related articles on the PHP Chinese website!