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 Gleep on 12/20/06 19:34

On Wed, 20 Dec 2006 10:45:02 +0100, Els <els.aNOSPAM@tiscali.nl> wrote:

>Hi all,
>
>Sorry for the bad subject line, I wouldn't know how to describe this.
>I'm sure this is common knowledge for anyone who knows PHP, i.e. not
>me, but I can't find the answer online.
>
>I'm just looking for a way to write the following in a shorter way:
>if ($a == 1 || $a == 2 || $a == 3 || $a == 4 || $a == 17 || $a == 30)
>
>Something that equates to "if $a == one of ((1 - 4), 17, 30)"
>
>TIA,





In situation like this I like to use in_array function

$numbers = array(1, 2, 3, 4, 17, 30 );
if ( in_array($a , $numbers) ) {
echo "have a match";
}

 

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

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