Home  >  Article  >  Backend Development  >  Differences between PHP functions isset and array_key_exists

Differences between PHP functions isset and array_key_exists

WBOY
WBOYOriginal
2016-07-25 08:56:23942browse
This article introduces the differences in usage of PHP's two functions isset and array_key_exists. Friends in need can refer to them. PHP determines whether the index value of an array exists. Generally, isset and array_key_exists are used. For example:
<?php isset($a['key'])
array_key_exists('key', $a)
The array_key_exists function will tell you exactly whether a key exists in the array, while isset just returns the status of whether the key value is null. Suppose you are given the following array: $a = array('key1' => '123', 'key2' => null); Use these two methods to determine the existence of key values. The results are as follows:
<?php isset($a['key1']);             // true
array_key_exists('key1', $a);  // true

isset($a['key2']);             // false
array_key_exists('key2', $a);  // true
Regarding the execution efficiency of these two functions: From the perspective of the PHP engine itself, the bottom layer is implemented in C language, and array_key_exists and isset should be very fast. If the number of operations is thousands or tens of thousands, the performance of isset should be more significant in this case.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn