Link to home
Start Free TrialLog in
Avatar of iceman19330
iceman19330

asked on

!= operator question

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')) {

Open in new window

Avatar of zappafan2k2
zappafan2k2

Try && instead of ||
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 !==
ASKER CERTIFIED SOLUTION
Avatar of zappafan2k2
zappafan2k2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the logic is the same in result :P
if NOT (9 OR 10) equals if NOT 9 OR NOT 10
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.
Avatar of iceman19330

ASKER

thank you