0

此代码片段只是较大 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;
}

知道这有什么不正确的吗?

4

2 回答 2

0

感谢您的回复,有人提示我尝试使用 array() 语法而不是 [ ] 语法,这似乎使代码正常工作。所以我现在假设这是一个解决方案。

于 2012-11-27T23:52:28.260 回答
-3

删除每个案例的最后一个 Breaks:

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"];
    }
}
于 2012-11-27T23:42:44.953 回答