note 49868 deleted from control-structures.switch by betz
| From: | betz@php.net | Date: | Mon, 04 Apr 2005 09:00:10 +0000 |
| Subject: | note 49868 deleted from control-structures.switch by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-87420@lists.php.net to get a copy of this message | ||
Note Submitter: jaw0121 at unt dot edu
----
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";
}