2013-10-14 146 views
0

下面是我的代码。相当直线前进。只有默认条件正在执行。注释掉其他语句是否有效。我正试图用开关统计来代替。为什么我的PHP case语句不起作用?

$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. */ 

非常感谢你提前

回答

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 
} 

有一个详细阅读http://php.net/manual/control-structures.switch.php

相关问题