168 posts
  • Referred between 1 and 9 users
  • Bought between 1 and 9 items
  • Has been a member for 4-5 years
  • Pakistan
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
MsTrends says

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 :)

659 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 50 and 99 users
  • Sold between 10 000 and 50 000 dollars
  • United States
luckykind says

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…

168 posts
  • Referred between 1 and 9 users
  • Bought between 1 and 9 items
  • Has been a member for 4-5 years
  • Pakistan
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
MsTrends says

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 .

168 posts
  • Referred between 1 and 9 users
  • Bought between 1 and 9 items
  • Has been a member for 4-5 years
  • Pakistan
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
MsTrends says

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

by
by
by
by
by
by