这是正确的格式吗?当我尝试使用它时,它给了我一个没有错误信息的空白页面。
$type = $row['page_type'];
$art = "Article";
$vid = "Video";
$pho = "Photo";
$link = "Link";
if ( $type === $art ) {
$page = "art.php";
} elseIF ($type === $vid) {
$page = "vid.php";
} elseIF ($type === $pho) {
$page = "photo.php";
} else {
} elseIF ($type === $link) {
$page = "link.php";
} else {
echo("Error");
}
答案 0 :(得分:6)
您还有一个}else{
if ( $type === $art ) {
$page = "art.php";
}elseif($type === $vid) {
$page = "vid.php";
}elseif($type === $pho) {
$page = "photo.php";
// This should not be here --> }else{
}elseif($type === $link) {
$page = "link.php";
}else{
echo("Error");
}
编辑:
你也可以使用哈希:
$h = array("Article"=>"article.php", "Video"=>"vid.php", ...);
if(array_key_exists($type, $h)){
$page = $h[$type];
}else{
echo "Error";
}