173 posts
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
+2 more
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
  • Has been part of the Envato Community for over 6 years
  • Has referred 50+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
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…

173 posts
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
+2 more
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 .

173 posts
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
+2 more
MsTrends says

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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by