Solved

# != operator question

Posted on 2011-05-04
277 Views
Last Modified: 2012-05-11
the code works if I remove the or portion but I need to check to make sure its not either 9 or 10.  I am not sure what I am doing wrong
``````if((\$row['cnid'] != '9') || (\$row['cnid'] != '10')) {
``````
0
Question by:iceman19330
6 Comments

LVL 12

Expert Comment

Try && instead of ||
0

LVL 27

Expert Comment

So to be complete
if((\$row['cnid'] != '9') && (\$row['cnid'] != '10'))

if the cnid is not 9 AND is not 10 - do something
Mind that you're comparing the string value '9' and '10'
To check if the \$row['cnid'] is not the value and the type integer you would use !==
0

LVL 12

Accepted Solution

Another way to write it would be
``````if (!(\$row['cnid'] == '9' || \$row['cnid'] == 10)) {
``````
if that makes more sense.

It's all about the logic.
0

LVL 27

Expert Comment

the logic is the same in result :P
if NOT (9 OR 10) equals if NOT 9 OR NOT 10
0

LVL 107

Expert Comment

The "or" condition is evaluated from left to right in this sequence.  So if you give it 10, the if() statement will be satisfied that 10 is not 9, and no further tests will be done.  That is why you want the && instead of the || here.
0

Author Closing Comment

thank you
0

## Write Comment

Please enter a first name

Please enter a last name

We will never share this with anyone.

## Featured Post

This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

#### 794 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!