You are here: Re: [PHP] multiple OR's « PHP « IT news, forums, messages
Re: [PHP] multiple OR's

Posted by Chris Shiflett on 03/17/05 20:32

AndreaD wrote:
> Looking for the most code efficient way to do multiple boolean OR's on one
> line
>
> if ($name==andrea) OR ($name==john)

If you put an opening brace after that, you'll get a parse error. You're
also treating andrea and john as constants, which I'm guessing isn't
what you mean. I think you were wanting:

if ($name == 'andrea' || $name == 'john')

If you have a bunch of these conditions, a switch might be convenient:

switch ($name)
{
case 'andrea':
case 'john':
case 'chris':
case 'rasmus':
case 'andi':
case 'zeev':
echo 'The name was one of those';
break;
default:
echo 'The name wasn't one of those';
}

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

 

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

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