Is there a better way to loop two associative arrays to match their values?
<p>I'm parsing the HTTP_ACCEPT_LANGUAGE header to get users' language and I'm building a class to do that.</p>

<p>Actually I build an associative array ("$this->user_lang") where keys are the language (such as "en-us", "it-it", "it-ch" etc) and the value is the quality factor (so I can order languages).
Then I have another associative array named "$this->installed_langs" where I declare supported language and locales (in the form "en" => "en_US", "it" => "it_IT").</p>

<p>All I want to do is try to match one of the key of "$this->user_lang" with one of the "$this->installed_langs" (without care of the local zone after the "-") and return the first occurrence (with no care for other matching case).</p>

<p>I ended up with this method but it seems a bit too complex...</p>

<pre><code>public function show() {
    $g_locale = null;
    foreach ($this-&gt;user_lang as $lang =&gt; $q) {
        foreach($this-&gt;installed_langs as $valid =&gt; $locale) {
            if (strpos($lang, $valid) !== false) {
                if ($g_locale === null) $g_locale = $locale;
            }
        }
    }
    // debug:
    echo $g_locale;
}
</code></pre>

<p>I hope I have explained it well, btw if you need more informations, please, ask me.</p>
