将关联数组值传递给$ _get

时间:2012-06-30 20:00:37

标签: php arrays associative-array

我正在尝试使用关联数组构建一个url查询,如下所示:

http://website.com/go.php?status=0&day=monday

这是我的代码,但它只返回单词数组。

$status = $_GET["status"];

$day= $_GET["day"] = array(
    "monday" => "one",
    "tuesday" => "two",
);

echo $status . " " . $day;

1 个答案:

答案 0 :(得分:3)

使用$_GET['day']作为数组的键:

$days = array("monday" => "one", "tuesday" => "two");

// Test if your array $day contains a key
// equivalent to the value in $_GET
// (only if $_GET['day'] was passed in the first place)
if (isset($_GET['day'] && isset($days[$_GET['day']])) {
  echo $status . " " . $days[$_GET['day']];
}
else echo "No such day...";