Kraken\Util\Support\ArraySupport::exists PHP Method

exists() public static method

Check if given key exists in array with dot notation support.
public static exists ( array $array, string $key ) : boolean
$array array
$key string
return boolean
    public static function exists($array, $key)
    {
        $key = static::normalizeKey($key);
        if ($key === null || $key === '' || static::isEmpty($array)) {
            return false;
        }
        $keys = explode('.', $key);
        $currentElement = $array;
        foreach ($keys as $currentKey) {
            if (!is_array($currentElement) || !array_key_exists($currentKey, $currentElement)) {
                return false;
            }
            $currentElement = $currentElement[(string) $currentKey];
        }
        return true;
    }

Usage Example

示例#1
0
 /**
  * @override
  * @inheritDoc
  */
 public function exists($key)
 {
     return ArraySupport::exists($this->config, $key);
 }