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')) {
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 !==
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the logic is the same in result :P
if NOT (9 OR 10) equals if NOT 9 OR NOT 10
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.
ASKER
thank you