Re: foreach on a 3d array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



$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.
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")

thnx,
Chris

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux