1
我有在PHP
多維數組鍵,下面的代碼:功能,如多維數組
<?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");
?>
當我在與域名.com網站,應該呼應的鍵值「可用」在域名鍵(「第一」) - 我們有一個愉快的一天。
當我在網站上使用域名.eu時,它應該寫入關鍵字「AVAILABLE」的值,但是在另一個域名關鍵字(「第二個」)中 - 我們沒有愉快的一天。
我該如何做這項工作?稍後將會有更多的鍵$weather
。
'myWeather'無法看到'$ weather'數組,因爲它定義在函數範圍之外 – billyonecan