Difference between php array_key_exists () and isset (), issetarraykeyexists
Php array_key_exists is used to check whether a key name exists in the array, and isset can also be used to check whether a key name exists in the array. What is the difference between them? This article will explain the differences between array_key_exists () and isset ().
The basic difference is that isset () can be used for arrays and variables, while array_key_exits () can only be used for arrays.
However, the main difference is the return value under the specified conditions.
Now let's verify the main difference.
Array_key_exists ()
Array_key_exists () checks the existence of the key value. This function returns TRUE if 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 ()
Unlike arrry_key_exitst (), isset () checks the key and value at the same time. It returns true only when the key exists and 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
Conclusion
This article describes the main differences between the two functions mentioned above. pay more attention when using these two functions in the future!
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!