Difference between php array_key_exists () and isset (), issetarraykeyexists

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.