$availableValues) { $availableQuality = (float)$availableQuality; if ($availableQuality === 0.0) { continue; } foreach ($availableValues as $availableValue) { $matchingGrade = static::_matchLanguage($acceptedValue, $availableValue); if ($matchingGrade > 0) { $q = (string)($availableQuality * $matchingGrade); if ($q === '1') { $q = '1.0'; } if (!isset($matches[$q])) { $matches[$q] = array(); } if (!in_array($availableValue, $matches[$q])) { $matches[$q][] = $availableValue; } } } } } krsort($matches); return $matches; } /** * Compare two language tags and distinguish the degree of matching * * @return float */ protected static function _matchLanguage($a, $b) { $a = explode('-', $a); $b = explode('-', $b); for ($i = 0, $n = min(count($a), count($b)); $i < $n; $i++) { if ($a[$i] !== $b[$i]) break; } return $i === 0 ? 0 : (float)$i / count($a); } }