Re: multiple OR's

From: Date: Thu, 17 Mar 2005 18:32:34 +0000
Subject: Re: multiple OR's
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-210997@lists.php.net to get a copy of this message
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/

« previous php.general (#210997) next »