Jump to content

PHP IF || Condition not working


Tenaciousmug

Recommended Posts

if($this->color=="Blue" || $this->color=="Green" || $this->color=="Red" || $this->color=="Yellow") {
return true;
} else {
return false;
}

 

This is returning false, when it should be returning true because $this->color DOES equal "Red"...

I can NEVER EVER get these conditional things to work UNLESS it's &&, but I even tried:

!$this->color != "Red" && .........

 

as well to see if that would work even though that's really confusing.

 

Can someone help me finally understand this stupid OR stuff?

Link to comment
Share on other sites

if($this->color=="Blue" || $this->color=="Green" || $this->color=="Red" || $this->color=="Yellow") {
return true;
} else {
return false;
}

 

This is returning false, when it should be returning true because $this->color DOES equal "Red"...

I can NEVER EVER get these conditional things to work UNLESS it's &&, but I even tried:

!$this->color != "Red" && .........

 

as well to see if that would work even though that's really confusing.

 

Can someone help me finally understand this stupid OR stuff?

 

try this or add an if next to your } else {

	if($this->color=="Blue" || $this->color=="Green" || $this->color=="Red" || $this->color=="Yellow") {
return false; 
} else if ($this->color=="Blue" || $this->color=="Green" || $this->color=="Red" || $this->color=="Yellow") {
        return true;
}

 

 

Link to comment
Share on other sites

There's nothing wrong with the code you posted, provided $this->color contains exactly any one of those values. What does $this->color contain, exactly? And are you sure?

 

To what i c in your code is this $this->color=="Blue" this will show in blue i guess to what u have in your code.give the two option a try and see if any them work for you.

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.