【发布时间】:2011-09-21 06:57:04
【问题描述】:
我正在尝试使用 break 概念,但我也在使用一些内置的 PHP 函数来只允许某些值进入 get 函数。
$allowedKeys = array(
'route'
);
$options = array(
'chapter_1' => 'chapter_1',
'chapter_2' => 'chapter_2',
'chapter_3' => 'chapter_3'
);
$_GET = array_intersect_key($_GET, array_flip($allowedKeys));
if($_GET[$allowedKeys[0]] && array_key_exists($_GET[$allowedKeys[0]], $options)) {
if($_GET[$allowedKeys[0]] == $options[0]) {
/* This is where I'm trying to see if route=chapter_1 then do something.
The logic I'm trying to write is if the route is chapter_1 then print
out the content from chapter 1 How can determine this? */
echo "Hello";
}
}
为什么这段代码没有回显“hello”?
【问题讨论】:
-
$_GET数组中有更多的键为什么重要?如果你不想要它们,那就不要使用它们。 -
这怎么应该投反对票?
-
可能是因为问题不清楚。为什么
$options是一个键值相等的数组? -
问题显然很清楚。