Differences between isset and array_key_exists in PHP functions _ PHP Tutorial

Source: Internet
Author: User
Differences between isset and array_key_exists in PHP functions. The isset and array_key_exists methods are generally used to determine whether the index value of a PHP array exists. Isset ($ a [key]) array_key_exists (key, $ a) array_key_exists is used to determine whether the index value of a PHP array exists. issetAnd array_key_existsTwo methods.

isset($a['key'])array_key_exists('key', $a)

array_key_existsTo tell you exactly whether an array has a keyissetOnly whether the return key value isnull. That is to say, assume that the following array is given:

$a = array('key1' => '123', 'key2' => null);

Use these two methods to determine the existence of the key value:

isset($a['key1']);             // truearray_key_exists('key1', $a);  // trueisset($a['key2']);             // falsearray_key_exists('key2', $a);  // true

From the PHP engine itself, the underlying layer is implemented in C language,array_key_existsAndissetIt should be fast. If the number of operations is more than timesissetPerformance should be more significant.

If the index value of the sort PHP array exists, the isset and array_key_exists methods are generally used. Isset ($ a ['key']) array_key_exists ('key', $ a) array_key_exists exact...

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.