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) Copy after login
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 Copy after login
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.
|