Dotan Cohen wrote:
On 24/10/06, Chris Boget <[EMAIL PROTECTED]> wrote:
> $languages = array(
>    "af"  => array("Afrikaans", "Afrikaans", "South Africa"),
>    "sq"  => array("Albanian", "Shqipe", "Albania")        );
>
> foreach ($languages as $language){
>    if (  strstr( $_HTTP_ACCEPT_LANGUAGE, $language)  ) {
>        print"<center>You are from ".$language[2]."!</center>";
>    }
> }

What you want is something like this:

foreach ($languages as $language => $valueArray ){
   if (  strstr( $_HTTP_ACCEPT_LANGUAGE, $language)  ) {
       print"<center>You are from ".$valueArray[2]."!</center>";
   }
}

Your example is setting the variable $language to the array for each
iteration.

Thanks, I see what I was missing.

So the first iteration,

$language is set to array("Afrikaans", "Afrikaans", "South Africa")

and the second iteration,

$language is set to array("Albanian", "Shqipe", "Albania")

That much I knew. Thanks, Chris.

Dotan Cohen

http://essentialinux.com/
http://technology-sleuth.com/

Why not just do

if(isset($language[$_HTTP_ACCEPT_LANGUAGE])) {
print '<center>You are from '.$language[$_HTTP_ACCEPT_LANGUAGE][3].'!</center>';
} else {
        print '<center>where are you from?!</center>';
}

using strstr is pretty slow, and considering you made the indices correspond to the actual value you're checking em for... this is a lot faster ^^ (and cleaner IMO)

- tul

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to