我正在使用多维数组来保存给定页面的变量。我正在尝试从 url 中获取一个字符串,并将其与我的模板数组中的一个数组匹配,以提取正确的变量以显示在页面上。
这是我的数组:
$template = array(
"index" => array(
"title" => "Dashboard",
"model" => "model/dash.php"
),
"input" => array(
"title" => "Dashboard",
"model" => "model/input.php"
),
"jobboard" => array(
"title" => "Job Board",
"model" => "model/job_board.php"
),
"jobcreate" => array(
"title" => "Job Creator",
"model" => "model/job_create.php"
)
);
这是我用来尝试验证页面的内容:
if(isset($_GET['page'])){ $page = $_GET['page']; }
if(in_array($page, $template)){
$title = $template[$page]['title'];
$model = $template[$page]['model'];
echo "yes";
}else{
$title = $template['index']['title'];
$model = $template['index']['model'];
echo "no";
}
这echo "yes/no";
就是我用来调试它是否工作的东西,但无论我做了什么,它都会继续输出不。