|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-02-21 23:55 UTC] 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;
}
}
?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 04:00:01 2025 UTC |
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")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.