Edit report at http://bugs.php.net/bug.php?id=32059&edit=1
ID: 32059 User updated by: scooley at apple dot com Reported by: scooley at apple dot com Summary: ranges in switch Status: Bogus Type: Feature/Change Request Package: *General Issues Operating System: mac os x PHP Version: 5.0.3 Block user comment: N New Comment: fine with me. Previous Comments: ------------------------------------------------------------------------ [2010-11-15 20:40:54] paj...@php.net not a bug > bogus ------------------------------------------------------------------------ [2010-11-15 19:15:41] scooley at apple dot com Hey, so it's been pointed out to me that this is possible already. switch($var) { case ($var <=9): { do_this(); break; } case ($var >= 10) && ($var <= 100) : { do_something(); break; } } Basically, the cases just need to evaluate to true or false in order for the code within to run, so you can do comparisons and ranges; you just need to form them correctly. ------------------------------------------------------------------------ [2010-11-15 14:44:53] scratch65535 at att dot net I too think it would be very convenient to allow a range as a case, e.g. switch( $somevar ) { case 1..5 : // code & break case 6..23 : // code & break // etc } (I also think it'd be very convenient if bugzilla didn't claim "incorrect captcha" when the problem is "i can't set a cookie") ------------------------------------------------------------------------ [2005-02-21 23:55:17] scooley at apple dot com Description: ------------ why not some behavior like this? ... switch($var) { case <= 9: { echo "less than ten"; break; } case 10: { echo "ten exactly"; break; } case >10 <> <15: { echo a range of values? why not?"; break; } case >= 15: { echo greater than or equal to fifteen"; break; } default: { echo what am I not thinking of here? break; } } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=32059&edit=1