note 105405 deleted from control-structures.switch by danbrown
| From: | danbrown@php.net | Date: | Wed, 17 Aug 2011 15:44:04 +0000 |
| Subject: | note 105405 deleted from control-structures.switch by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182547@lists.php.net to get a copy of this message | ||
Note Submitter: bryan schmidt
----
In response to varnavruz, his example script will never show "That's slooooow" as a
reply since the switch structure will pick the first case is satisfied. Therefore, if $totaltime is
greater than 10, it will also be greater than 1, thereby always showing "Not fast!" as a
reply.
Plus, the value 1 is not accounted for, so a greater than or equal to must be used somwhere if a
test for 1 itself is not present.
A simple re-ordering of the case scenarios will fix this issue:
<?php
switch ($totaltime) {
case ($totaltime < 1):
echo "That was fast!";
break;
case ($totaltime > 10):
echo "That's slooooow";
break;
case ($totaltime >= 1):
echo "Not fast!";
break;
}
?>