You are here: Re: newbie alert: how to write this in a shorter way « PHP Language « IT news, forums, messages
Re: newbie alert: how to write this in a shorter way

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация