$entry) { $domain = explode("/", $entry["url"])[2]; $sim = similar_text($domain, $_GET['q'], $perc); if (substr($domain, 0, 4) === "www.") { $domainstr = substr($domain, 4); } else { $domainstr = $domain; } $domains[] = [ "id" => $id, "url" => "https://" . $domain . "/", "domain" => $domainstr, "relevance" => $perc / 50 - 1 ]; } usort($domains, function($a, $b) { return $a['relevance'] <=> $b['relevance']; }); $domains = array_reverse($domains); header("Location: " . $domains[0]['url']); die(); }