Jump to content

If page id does not equal current page issue


a-ok
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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