This is a discussion on newbie alert: how to write this in a shorter way within the alt.comp.lang.php forums, part of the PHP Programming Forums category; hackajar@gmail.com wrote: > I was thinking about that when I woke up this morning ;) Good catch! > > ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |