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)
<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);
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
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.