Jump to content

Recommended Posts

Posted

Is there any reason why this wouldn't work?

<?php if ($page->id !== 1037 || $page->id !== 1038) : ?>

I have no problem using if the page id equals the current page but not if not.

Posted
5 minutes ago, adrian said:

Are you sure you don't want && rather than || :)

Haha! No I don't believe so? If the page isn't 1037 or 1038 then do this...?

Posted (edited)

What Adrian said. You need &&. Try it, it will work :).

If page ID is not 1037 AND it is not 1038 AND it is not 1039.....

Edited by kongondo
  • Like 5
Posted

 

OR             AND

1037 F T F T   F T F T

1038 F F T T   F F T T

     F T T T   F F F T

  • Like 5
Posted

Think I got this right. If I haven't, then I accept all mockery :P

if 1037 !== 1037 || 1037 !== 1038
FALSE || TRUE - runs

if 1038 !== 1037 || 1038 !== 1038
TRUE || FALSE - runs

if 100 !== 1037 || 100 !== 1038
TRUE || TRUE - runs

//...seems this || block will ALWAYS run...
// ...what about with &&...


if 1037 !== 1037 && 1037 !== 1038
FALSE && TRUE - doesnt run

if 1038 !== 1037 && 1038 !== 1038
TRUE && FALSE - doesnt run

if 100 !== 1037 && 100 !== 1038
TRUE && TRUE - runs

 

Posted

No mockery from this group. We're here to help.
If you have a statement comparing two conditions (eg. variable to1037, and variable to 1038) then there are four possible combinations: FF FT TF TT. Basically, for every n elements there are 2^n possible outcomes.

Example 1.
If you want to perform a conjunction (AND) then the statement is true only when both components are true, as follows:
Assume $page->id = 100
IF ($page->id !== 1037) AND ($page->id !== 1038) THEN TRUE

Example 2.
If you want to perform a disjunction (OR) then the statement is true when either component is true, as follows:
Assume $page->id = 100
IF ($page->id !== 1037) OR ($page->id !== 1038) THEN TRUE

The problem you are experiencing is wanting to use the disjunctive case, as in Example 2. Because when the $page->id does not equal one of the test values (1037 or 1038) the result will also be true, which is not the desired outcome.

Hope this helps.

  • Like 6

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...