此代码段只是较大的php文件的一小部分。目前,该文件在运行时不会生成任何内容(与PHP相似)但是当我注释掉本节(下面)时,文件会执行。因此,我只能相信此代码段中的某些内容会阻止PHP正常运行。也许是嵌套的switch语句?
switch($interval)
{
case "week":
$active_date = date('N', $endTime);
switch($active_date)
{
case 1:
$categories = ["Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday","Monday"];
break;
case 2:
$categories = ["Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"];
break;
case 3:
$categories = ["Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"];
break;
case 4:
$categories = ["Friday","Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday"];
break;
case 5:
$categories = ["Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"];
break;
case 6:
$categories = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
break;
case 7:
$categories = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
break;
}
break;
case "month":
$categories = ["Three Weeks Ago","Two Weeks Ago","Last Week","This Week"];
break;
case "year":
$active_date = date('n', $endTime);
switch($active_date)
{
case 1:
$categories = ["February","March","April","May","June","July","August","September","October","November","December","January"];
break;
case 2:
$categories = ["March","April","May","June","July","August","September","October","November","December","January","February"];
break;
case 3:
$categories = ["April","May","June","July","August","September","October","November","December","January","February","March"];
break;
case 4:
$categories = ["May","June","July","August","September","October","November","December","January","February","March","April"];
break;
case 5:
$categories = ["June","July","August","September","October","November","December","January","February","March","April","May"];
break;
case 6:
$categories = ["July","August","September","October","November","December","January","February","March","April","May","June"];
break;
case 7:
$categories = ["August","September","October","November","December","January","February","March","April","May","June","July"];
break;
case 8:
$categories = ["September","October","November","December","January","February","March","April","May","June","July","August"];
break;
case 9:
$categories = ["October","November","December","January","February","March","April","May","June","July","August","September"];
break;
case 10:
$categories = ["November","December","January","February","March","April","May","June","July","August","September","October"];
break;
case 11:
$categories = ["December","January","February","March","April","May","June","July","August","September","October","November"];
break;
case 12:
$categories = ["January","February","March","April","May","June","July","August","September","October","November","December"];
break;
}
break;
}
有什么不正确的想法?
答案 0 :(得分:0)
感谢您的回复,我被暗示尝试使用array()语法而不是[]语法,并且看起来代码有效。所以我现在假设这是一个解决方案。
答案 1 :(得分:-3)
删除每个案例的最后一个分组:
switch($interval)
{case "week":
$active_date = date('N', $endTime);
switch($active_date)
{
case 1:
$categories = ["Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday","Monday"];
break;
case 2:
$categories = ["Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"];
break;
case 3:
$categories = ["Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"];
break;
case 4:
$categories = ["Friday","Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday"];
break;
case 5:
$categories = ["Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"];
break;
case 6:
$categories = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
break;
case 7:
$categories = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
}
break;
case "month":
$categories = ["Three Weeks Ago","Two Weeks Ago","Last Week","This Week"];
break;
case "year":
$active_date = date('n', $endTime);
switch($active_date)
{
case 1:
$categories = ["February","March","April","May","June","July","August","September","October","November","December","January"];
break;
case 2:
$categories = ["March","April","May","June","July","August","September","October","November","December","January","February"];
break;
case 3:
$categories = ["April","May","June","July","August","September","October","November","December","January","February","March"];
break;
case 4:
$categories = ["May","June","July","August","September","October","November","December","January","February","March","April"];
break;
case 5:
$categories = ["June","July","August","September","October","November","December","January","February","March","April","May"];
break;
case 6:
$categories = ["July","August","September","October","November","December","January","February","March","April","May","June"];
break;
case 7:
$categories = ["August","September","October","November","December","January","February","March","April","May","June","July"];
break;
case 8:
$categories = ["September","October","November","December","January","February","March","April","May","June","July","August"];
break;
case 9:
$categories = ["October","November","December","January","February","March","April","May","June","July","August","September"];
break;
case 10:
$categories = ["November","December","January","February","March","April","May","June","July","August","September","October"];
break;
case 11:
$categories = ["December","January","February","March","April","May","June","July","August","September","October","November"];
break;
case 12:
$categories = ["January","February","March","April","May","June","July","August","September","October","November","December"];
}
}