PHP: Multiple conditions with NOT operator is not working


Hi, Hope u people will be fine. I’m working on a theme in which i want to use multiple php if conditions with multiple not operators (example is below), but when i execute following php code, it always returns true (mean content in always parenthesis always executed) even no condition is true. I want to ask what is the problem in following code. Is there any specific syntax or rule for using multiple != operator in php conditions. And i am amazed to see that if i use following code by replacing != operator with == operator it is working fine.

<?php if ($sidebar != "portfolio" || $sidebar != "right" || $sidebar != "left") { ?>

----- content which will be executed if above condition returns true -------

 <?php } ?>

Waiting for your kind replies. and sorry for my bad english :slight_smile:


you need to replace your ORs ( || ) with ANDs ( && )

A couple of != with an OR ( || ) will always equal true because that string variable will only equal one thing and not be the other…


Thanks for reply, but replacing all || with && will not cause to execute the stamement in parenthesis only if all conditions all TRUE?

I want to execute the statement even if only one condition is TRUE.


@luckykind: you rock. i just tried your suggested solution, its working fine. Although i still can’t understand the logic. :slight_smile: