下面是我的代码。挺直前的。只有默认条件正在执行。注释掉其他if语句确实有效。我试图用开关声明替换。
$currCat = (int)$_GET['cPath'];
switch ($currCat) {
case 4:
$tpl_page_body = '/tpl_product_info_display_threads.php';
case 1:
$tpl_page_body = '/tpl_product_info_display_canvas.php';
case 3:
$tpl_page_body = '/tpl_product_info_display_belts.php';
case 85:
$tpl_page_body = '/tpl_product_info_display_books.php';
case 75:
$tpl_page_body = '/tpl_product_info_display_beltsDEV.php';
default:
$tpl_page_body = '/tpl_product_info_display.php';
}
/*
if($currCat == 4) {
$tpl_page_body = '/tpl_product_info_display_threads.php';
} elseif ($currCat == 1) {
$tpl_page_body = '/tpl_product_info_display_canvas.php';
etc. etc. */
非常感谢你提前
答案 0 :(得分:7)
你需要在每个案例之间放置break
语句,除非你想让它们级联(我假设你没有)
switch ($currCat) {
case 4 :
$tpl_page_body = '/tpl_product_info_display_threads.php';
break;
case 1 :
$tpl_page_body = '/tpl_product_info_display_canvas.php';
break;
// and so on
}