Re: Using the OR operator in an IF statement
| From: | Jason Wong | Date: | Sat, 08 Jan 2005 13:02:31 +0000 |
| Subject: | Re: Using the OR operator in an IF statement | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-205865@lists.php.net to get a copy of this message | ||
On Saturday 08 January 2005 19:02, Tim Burgan wrote:
> Can someone please correct me on my efforts below.
> If I have a condition where I want to test if a variable is not equal to
> "student", "staff", or "admin".. what's the simplest was to
> achieve that?
>
> Here's what I tried.. that didn't work:
>
> <?php
> if ( ($_POST['usertype'] != "student") || ($_POST['usertype']
> !=
> "staff") || ($_POST['usertype'] != "admin") )
> {
> // ...
> }
> ?>
You need to use 'AND' (or '&&').
Or you can use in_array():
$usertype = array('student', 'staff', 'admin');
if (in_array($_POST['usertype'], $usertype)) {
// valid usertype;
} else {
// invalid usertype
}
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
New Year Resolution: Ignore top posted posts