Ze zadaného pole vybere jen ty položky, které mají klíč udaný v druhém poli.
@param array|\ArrayAccess $array Asociativní pole
@param array $requiredKeys Obyčejné pole klíčů
@return array
331711
static function filterByKeys($array, $requiredKeys) {
		if (is_array($array)) {
			return array_intersect_key($array, array_fill_keys($requiredKeys, true));
		}
		if ($array instanceof \ArrayAccess) {
			$ret = array();
			foreach ($requiredKeys as $k) {
				if (isset($array[$k])) {
					$ret[$k] = $array[$k];
				}
			}
			return $ret;
		}

		throw new \InvalidArgumentException("Argument must be an array or object with ArrayAccess");
	}
446418
public function setFormFieldRequired($array, $fieldName, $isRequired = false)
    {
        if (!empty($array['input_filter'])) {
            foreach ($array['input_filter'] as $keyElement => $element) {
                if ($keyElement == $fieldName) {
                    $array['input_filter'][$keyElement]['required'] = $isRequired;
                }
            }
        }

        return $array;
    }
218660
public static function expandKey(array $array, string $key): array
	{
		if(strpos($key, '*') === false)
		{
			throw new RuntimeException('The key must contain at least one wildcard character.');
		}

		$keys = (array) $key;

		start:

		$expanded = [];

		foreach($keys as $key)
		{
			[$first, $remaining] = array_map('trim', explode('*', $key, 2), ['.', '.']);

			if(empty($first))
			{
				$value = $array;
			}
			elseif(is_array($value = static::get($array, $first)) === false)
			{
				continue;
			}

			foreach(array_keys($value) as $key)
			{
				$expanded[] = trim($first . '.' . $key . '.' . $remaining, '.');
			}
		}

		if(strpos($remaining, '*') !== false)
		{
			$keys = $expanded;

			goto start;
		}

		return $expanded;
	}
293126
public static function keyFlattening($array, $keys = []) {
		if (is_array($array)) {
			$result = [];
			foreach ($array as $key => $value) {
				$tmp_keys = $keys;
				$tmp_keys [] = $key;
				$result = array_merge($result, static::keyFlattening($value,$tmp_keys));
			}
			return $result;
		}

		$key = array_shift($keys);
		return [
			empty($keys) ? $key : sprintf('%s[%s]', $key, implode ('][', $keys)) => $array,
		];
	}
1268883
private function camelizeKeys(array $array)
    {
        $camelized = array();

        foreach ($array as $key => $value) {
            $camelized[$this->camelize($key)] = is_array($value)
                ? $this->camelizeKeys($value)
                : $value;
        }

        return $camelized;
    }
200588
private function getFieldKey(array $requestedFields = null): string
    {
        if (is_null($requestedFields)) {
            return 'no-field-key';
        }
        return $fieldKey = '.' . sha1(implode(',', $requestedFields));
    }
326821
public static function getSubArrayFromArrayByKeys(array $array, array $keys)
    {
        $result = [];

        foreach ($keys as $key) {
            if (array_key_exists($key, $array)) {
                $result[$key] = $array[$key];
            }
        }

        return $result;
    }
669705
public function setRequired($keys)
    {
        if(is_string($keys))
        {
            $this->setRequired(explode(",",$keys));
        }
        else
        {
            foreach($keys as $key)
            {
                if(!in_array($key, $this->required))
                    $this->required[] = $key;
            }
        }

        return $this;
    }
924755
protected function validateS3Config(array $config, array $requiredKeys)
    {
        foreach ($requiredKeys as $requiredKey) {
            if (!array_key_exists($requiredKey, $config)) {
                throw new InvalidConfigException($requiredKey);
            }
        }
    }
1280760
public static function key_exists($array, $key)
    {
        if (!is_array($array) and !$array instanceof ArrayAccess) {
            throw new InvalidArgumentException('First parameter must be an array or ArrayAccess object.');
        }

        is_object($key) and $key = (string) $key;

        if (!is_string($key)) {
            return false;
        }
        if (array_key_exists($key, $array)) {
            return true;
        }
        foreach (explode('.', $key) as $key_part) {
            if (($array instanceof ArrayAccess and isset($array[$key_part])) === false) {
                if (!is_array($array) or ! array_key_exists($key_part, $array)) {
                    return false;
                }
            }
            $array = $array[$key_part];
        }
        return true;
    }
882136
public static function GetElementsByKeys (array $array, array $keys) {
		return array_filter(array_combine($keys, array_map(function ($key) use ($array) {
			return isset($array[$key]) ? $array[$key] : null;
		}, $keys)));
	}
1144040
function normalizeRequirement($requirement, $requirementKey = 0)
    {
        if (!is_array($requirement)) {
            $this->usageError('Requirement must be an array!');
        }

        if (!array_key_exists('condition', $requirement)) {
            $this->usageError("Requirement '{$requirementKey}' has no condition!");
        }

        if (!array_key_exists('name', $requirement)) {
            $requirement['name'] = is_numeric($requirementKey) ? 'Requirement #'.$requirementKey : $requirementKey;
        }

        if (!array_key_exists('mandatory', $requirement)) {
            if (array_key_exists('required', $requirement)) {
                $requirement['mandatory'] = $requirement['required'];
            } else {
                $requirement['mandatory'] = false;
            }
        }

        if (!array_key_exists('memo', $requirement)) {
            $requirement['memo'] = '';
        }

        return $requirement;
    }
594897
public static function getRequiredArgsError($args, $requiredArgs)
    {
        if (!is_array($args) && !is_object($args)) {
            return sprintf(__('invalid type "%s" for $args', 'themaster'), gettype($args));
        }
        if (!is_array($requiredArgs) && !is_object($args)) {
            return sprintf(__('invalid type "%s" for $requiredArgs', 'themaster'), gettype($requiredArgs));
        }

        $missing = array();
        foreach ($requiredArgs as $req) {
            if (!@isset($args[$req]) && !@isset($args->$req)) {
                $missing[] = $req;
            }
        }
        
        if (count($missing) == 0) {
            return false;
        } else {
            return sprintf(
                __('Missing %s as %s.', 'themaster'),
                self::readableList(
                    $missing,
                    ' '.__('and').' ',
                    ', ',
                    null,
                    '"'
                ),
                (count($missing) === 1 ? 'a key' : 'keys')
            );
        }
    }
931924
protected function checkRequiredRoutesValidity(array $routes, array $requiredRouteKeys): void
    {
        $routeKeys = array_keys($routes);
        foreach ($requiredRouteKeys as $requiredRouteKey) {
            if (! in_array($requiredRouteKey, $routeKeys)) {
                throw new ErrorException(
                    'The required « ' . $requiredRouteKey
                    . ' » route key is missing. Use the « setRoutes() » method to declare it.'
                );
            }
        }
    }
810644
static function checkAnyRequiredParameter(array $given, array $required)
    {
        try {
            
            foreach ($required as $key) {
                if (!empty($given[$key])) {
                    throw new RequiredParameterFound();
                }
            }
            
            $parameters = implode(', ', $required);
            throw new MissingRequiredParameterException(
                    "At least one parameter required: $parameters"
            );
            
        } catch (RequiredParameterFound $ex) {
            // we have one required parameter, thats all we need
        }
    }
1333623
public static function requiresProperties($keys, $array)
    {
        $keys = is_array($keys) ? $keys : [$keys];
        $missingKeys = array_keys(array_diff_key(array_flip($keys), $array));

        if (count($missingKeys) > 0) {
            list($one, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
            throw new MissingPropertiesException(
                'Missing properties '.implode(', ', $missingKeys).' for function '.$caller['function']
            );
        }
    }
1146043
public static function ensure_key_present($key, $array)
	{
		// ensure that the array we are checking is an array
		if (! is_array($array))
		{
			throw new ArraysException('Value of $array is not an array');
		}

		// if we are not checking an array of keys,
		// then just return array_key_exists check
		if (! is_array($key))
		{
			return array_key_exists($key, $array);
		}

		// gather the keys of the array
		$array_keys = array_keys($array);

		// itterate over the keys to check
		foreach ($key as $check_key)
		{
			// if the key does not exists
			if (! in_array($check_key, $array_keys))
			{
				// return false
				return false;
			}
		}

		// all keys exist
		return true;
	}