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
https://forums.phpfreaks.com/topic/262764-php-if-condition-not-working/
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;
}

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.