mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-01 11:39:41 +08:00
Fixes #11950: Improve BaseArrayHelper::keyExists speed
This commit is contained in:
committed by
Alexander Makarov
parent
466fc9db32
commit
c99acb6182
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user