note 49868 added to control-structures.switch
| From: | jaw0121 at unt dot edu | Date: | Thu, 10 Feb 2005 21:14:53 +0000 |
| Subject: | note 49868 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84813@lists.php.net to get a copy of this message | ||
Surprisingly, I saw no blogs on how to test a range of values using switch, so here's an
example:
switch(true)
{
case (intval($_POST['age']) <= 21):
echo "age <= 21";
break;
case (intval($_POST['age']) <= 29):
echo "22 <= age <= 29";
break;
case (intval($_POST['age']) <= 65):
echo "30 <= age <= 65";
break;
default:
echo "age > 65";
}
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49868
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49868&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49868&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49868&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49868&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49868&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49868&report=yes
Search -- http://master.php.net/manage/user-notes.php