re:Switch - Case Statement Questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I was just wondering after writting the code in version 2 here below, it turns out in testing that it actually PHP is not validating the expressions instead always I get the first case.

1.Using nested if statement {THE INTENDED BEHAVIOR}:
        if ($count > 14)
            $boxes = 3;
        elseif($count > 7 && $count <= 14)
            $boxes = 2;
        else
            $boxes = 1;

2. Using Switch {ALWAYS FIRST CASE!!!}

//        $boxes = 1;
//        switch ($count) {
//            case ($count > 14):                
//                $boxes = 3;
//                break;
//            case ($count > 7 && $count <= 14):
//                $boxes = 2;
//                break;
//            case ($count <= 7):
//            default :
//                $boxes = 1;
//                break;
//        }


Does anyone know the answer why using the Switch it always execute the first case ?

Many thanks

Omar
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux