【发布时间】:2012-11-22 23:35:09
【问题描述】:
switch($_SERVER["SCRIPT_NAME"]){
case "/index.php":
$this->pageId = 1;
break;
case "/shops/index.php":
$this->pageId = 2;
break;
case "/shops/dailydeals.php":
$this->pageId = 4;
break;
case "/shops/shops.php":
$this->pageId = 5;
break;
case "/shops/deals.php":
$this->pageId = 9;
break;
case "/shops/store.php":
$this->pageId = 10;
break;
case "/user/cashmail.php":
$this->pageId = 13;
break;
case "/user/cashmail.php":
$this->pageId = 13;
break;
default ;
$this->pageId = 1;
break;
}
你对上面的代码有什么看法?我正在尝试决定是否应该在我的 case 手臂上使用花括号。我的示例中的每个案例只有一行代码,所以我没有使用花括号。使用或不使用花括号之间是否存在性能差异?
【问题讨论】:
标签: php performance syntax switch-statement conditional-statements