src/Http/ContentNegotiation/LanguageMatcher.php
public function getBestLanguageMatch(array $supportedLanguages, array $languageHeaders): ?string
    {
        usort($languageHeaders, [$this, 'compareAcceptLanguageHeaders']);
        $rankedLanguageHeaders = array_filter($languageHeaders, [$this, 'filterZeroScores']);
        $rankedLanguageHeaderValues = $this->getLanguageValuesFromHeaders($rankedLanguageHeaders);

        foreach ($rankedLanguageHeaderValues as $language) {
            $languageParts = explode('-', $language);

            // Progressively truncate this language tag and try to match a supported language
            do {
                foreach ($supportedLanguages as $supportedLanguage) {
                    if ($language === '*' || implode('-', $languageParts) === $supportedLanguage) {
                        return $supportedLanguage;
                    }
                }

                array_pop($languageParts);
            } while (count($languageParts) > 0);
        }

        return null;
    }
public function getBestLanguageMatch(array $supportedLanguages, array $languageHeaders): ?string
    {
        usort($languageHeaders, [$this, 'compareAcceptLanguageHeaders']);
        $rankedLanguageHeaders = array_filter($languageHeaders, [$this, 'filterZeroScores']);
        $rankedLanguageHeaderValues = $this->getLanguageValuesFromHeaders($rankedLanguageHeaders);

        foreach ($rankedLanguageHeaderValues as $language) {
            $languageParts = explode('-', $language);

            // Progressively truncate this language tag and try to match a supported language
            do {
                foreach ($supportedLanguages as $supportedLanguage) {
                    if ($language === '*' || implode('-', $languageParts) === $supportedLanguage) {
                        return $supportedLanguage;
                    }
                }

                array_pop($languageParts);
            } while (count($languageParts) > 0);
        }

        return null;
    }
Gets the best language match between a list of supported languages and Accept-Language headers
This uses "lookup" matching per RFC-4647 section 3.4

@param array $supportedLanguages The list of supported languages
@param AcceptLanguageHeaderValue[] $languageHeaders The list of language headers to rank
@return string|null The best language match if one existed, otherwise null
@link https://tools.ietf.org/html/rfc4647#section-3.4