Home > Backend Development > PHP Tutorial > The difference between isset and array_key_exists in PHP functions_PHP tutorial

The difference between isset and array_key_exists in PHP functions_PHP tutorial

WBOY
Release: 2016-07-21 14:58:54
Original
833 people have browsed it

When determining whether the index value of a certain PHP array exists, two methods, <font face="NSimsun">isset</font> and <font face="NSimsun">array_key_exists</font>, are generally used.

isset($a['key'])
array_key_exists('key', $a)
Copy after login

<font face="NSimsun">array_key_exists</font> tells you exactly whether a certain key exists in the array, while <font face="NSimsun">isset</font> just returns the status of whether the key value is <font face="NSimsun">null</font>. That is, assuming the following array is given:

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

Use these two methods to determine the existence of key values. The results are as follows:

isset($a['key1']);             // true
array_key_exists('key1', $a);  // true

isset($a['key2']);             // false
array_key_exists('key2', $a);  // true
Copy after login

From the perspective of the PHP engine itself, the bottom layer is implemented in C language. Both <font face="NSimsun">array_key_exists</font> and <font face="NSimsun">isset</font> should be very fast. If the number of operations is thousands or tens of thousands, the performance of <font face="NSimsun">isset</font> should be more significant in this case.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363774.htmlTechArticleTo determine whether the index value of a PHP array exists, isset and array_key_exists are generally used. isset($a['key'])array_key_exists('key', $a) array_key_exists exactly...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template