a-ok Posted March 8, 2017 Share Posted March 8, 2017 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. Link to comment Share on other sites More sharing options...
adrian Posted March 8, 2017 Share Posted March 8, 2017 Are you sure you don't want && rather than || 3 Link to comment Share on other sites More sharing options...
a-ok Posted March 8, 2017 Author Share Posted March 8, 2017 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...? Link to comment Share on other sites More sharing options...
kongondo Posted March 8, 2017 Share Posted March 8, 2017 (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 March 8, 2017 by kongondo 5 Link to comment Share on other sites More sharing options...
rick Posted March 8, 2017 Share Posted March 8, 2017 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 5 Link to comment Share on other sites More sharing options...
SamC Posted March 9, 2017 Share Posted March 9, 2017 Think I got this right. If I haven't, then I accept all mockery 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 More sharing options...
rick Posted March 9, 2017 Share Posted March 9, 2017 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. 6 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now