|
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]
|