note 107786 deleted from function.array-key-exists by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 20:38:30 +0000 |
| Subject: | note 107786 deleted from function.array-key-exists by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218742@lists.php.net to get a copy of this message | ||
Note Submitter: Nik Tang
----
If you want to take the performance advantage of isset() while keeping the NULL element correctly
detected, use this:
if (isset(..) || array_key_exists(...))
{
...
}
Benchmark (100000 runs):
array_key_exists() : 205 ms
is_set() : 35ms
isset() || array_key_exists() : 48ms
Note:
The code for this check is very fast, so you shouldn't warp the code into a single function
like below, because the overhead of calling a function dominates the overall performance.
function array_check(...)
{
return (isset(..) || array_key_exists(...))
}