Jump to content

Correct use of the OR statement


brob

Recommended Posts

In that case you need AND, not OR.

[code]<?php
if ((!$member) && (!$nonmember)){
  // do whatever
}
?>[/code]

With OR, only one of the sides needs to be true for the whole statement to be true, with AND, both sides need to be true, which is what you're after.

Regards
Huggie
Link to comment
Share on other sites

Using negative tests with AND's and OR's can be confusing. You could also rewrite it like so:

<?php
if ( !($member || $nonmember) ) {
  // do whatever
}
?>

Using your original logic you are testing wether the person is "not a member" or "not a nonmember". I would assume that both of those can't be true at the same time. Thus, your test will always pass.
Link to comment
Share on other sites

[quote author=HuggieBear link=topic=123806.msg512331#msg512331 date=1169651868]
[quote author=mjdamato link=topic=123806.msg512326#msg512326 date=1169651760]
I would assume that both of those can't be true at the same time. Thus, your test will always pass.
[/quote]

Hence, the change to AND instead of OR :)[/quote]

Yes, absolutely. But, I was just trying to point out that it is confusing because most people don't think along the lines of "is he not a member and not a non member". They usually think along the lines of "is he not (a member or a non member)". That is the problem which the OP ran into, which is why I gave the other method which is more closely associated with how many people usually think.

There is nothing inherently right or wrong with either method. I was just giving another option.
Link to comment
Share on other sites

[quote author=chriscloyd link=topic=123806.msg513032#msg513032 date=1169718183]
$_SESSION['member'] or $_SESSION['nonmember']
[/quote]

Chris,

This is a good point, I had assumed that as the OP had only posted a snippet of code that they had already assigned the session variables to $member or $nonmember.

Huggie
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.