I'm having a multidimensional array in PHP
and the following code:
<?php
$weather = array (
"AVAILABLE" => array (
"first" => "We're having a nice day.",
"second" => "We're not having a nice day.",
"fifth" => "It's raining out there.",
"tenth" => "It's gonna be warm today."));
function getDomain() {
if (strpos($_SERVER['SERVER_NAME'], '.com') !== FALSE) {
return "first";
}
elseif (strpos($_SERVER['SERVER_NAME'], '.eu') !== FALSE) {
return "second";
}
else {
die();
}
}
function myWeather($string) {
$domain = getDomain();
return $weather[$string][$domain];
}
echo myWeather("AVAILABLE");
?>
When I am at web with domain .com, it should echo value of key "AVAILABLE" in domains key ("first") - We're having a nice day.
When I'll be in site with domain .eu, it should write value of key "AVAILABLE", but in another domains key ("second") - We're not having a nice day.
How can I make this work please? Later there will be more keys in array $weather
.