Fixes #11950: Improve BaseArrayHelper::keyExists speed

This commit is contained in:
Egor Verbitskiy
2016-07-15 04:53:25 -07:00
committed by Alexander Makarov
parent 466fc9db32
commit c99acb6182
2 changed files with 5 additions and 3 deletions

View File

@ -486,7 +486,9 @@ class BaseArrayHelper
public static function keyExists($key, $array, $caseSensitive = true)
{
if ($caseSensitive) {
return array_key_exists($key, $array);
// Function `isset` checks key faster but skips `null`, `array_key_exists` handles this case
// http://php.net/manual/en/function.array-key-exists.php#107786
return isset($array[$key]) || array_key_exists($key, $array);
} else {
foreach (array_keys($array) as $k) {
if (strcasecmp($key, $k) === 0) {