yii\helpers\BaseArrayHelper::keyExists PHP Method

keyExists() public static method

This method enhances the array_key_exists() function by supporting case-insensitive key comparison.
public static keyExists ( string $key, array $array, boolean $caseSensitive = true ) : boolean
$key string the key to check
$array array the array with keys to check
$caseSensitive boolean whether the key comparison should be case-sensitive
return boolean whether the array contains the specified key
    public static function keyExists($key, $array, $caseSensitive = true)
    {
        if ($caseSensitive) {
            // 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) {
                    return true;
                }
            }
            return false;
        }
    }