Posted by Ken Robinson on 12/26/06 01:44
hackajar@gmail.com wrote:
> I was thinking about that when I woke up this morning ;) Good catch!
>
> Maybe this would be more creative (not to complicate this even more;):
> <?php
>
> function checkA($a) {
> switch($a) {
> case 1:return true; break;
> case 2:return true; break;
> case 3:return true; break;
> case 4:return true; break;
> case 17:return true; break;
> case 30:return true; break;
> }
> return false;
> }
>
> if(checkA($a))echo "bingo!";
> ?>
If you're going to make this into a switch statement, group the "true"
values together:
<?php
function checkA($a) {
$retVal = false;
switch($a) {
case 1:
case 2:
case 3:
case 4:
case 17:
case 30:
$retVal = true;
break;
}
return ($retVal);
}
if (checkA($a)) echo 'Ok!';
?>
Ken
[Back to original message]
|