Forum Moderators: coopster

Message Too Old, No Replies

if ($name == x OR y)

         

scraptoft

9:09 pm on Oct 15, 2007 (gmt 0)

10+ Year Member



This is probably really simple but it's just flying right over my head. I'd appreciate if someone could give me a hand.

How can I achieve: if ($name == dave OR andy) {echo "Hello";}

mooger35

9:31 pm on Oct 15, 2007 (gmt 0)

10+ Year Member



if ($name == "dave" ¦¦ $name == "andy") {echo "Hello";}

edit: remember to retype ¦¦ as this forum breaks the pipes.

or use:

if ($name == "dave" OR $name == "andy") {echo "Hello";}

scraptoft

10:21 pm on Oct 15, 2007 (gmt 0)

10+ Year Member



Thanks very much mooger, saved me loads of time.

Regards

FourDegreez

2:49 am on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could create a function that checks whether a value is within an array, for example:

function in($value, $list) {
    for ($i = 0; $i < count($list); $i++) {
        if ($value == $list[$i])
            return true;
    }
    return false;
}

This can come in handy.

[edited by: FourDegreez at 2:50 am (utc) on Oct. 16, 2007]

eelixduppy

2:57 am on Oct 16, 2007 (gmt 0)



There is a function built for this already: in_array [php.net] :)