为什么我的PHP案例陈述不起作用?

Top*_*ato 0 php

下面是我的代码.挺直前的.只有默认条件正在执行.注释掉其他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. */
Run Code Online (Sandbox Code Playgroud)

非常感谢你提前

Phi*_*hil 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
}
Run Code Online (Sandbox Code Playgroud)

请仔细阅读http://php.net/manual/control-structures.switch.php