Tenaciousmug Posted May 19, 2012 Share Posted May 19, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/262764-php-if-condition-not-working/ Share on other sites More sharing options...
Davie33 Posted May 19, 2012 Share Posted May 19, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/262764-php-if-condition-not-working/#findComment-1346768 Share on other sites More sharing options...
PFMaBiSmAd Posted May 19, 2012 Share Posted May 19, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/262764-php-if-condition-not-working/#findComment-1346769 Share on other sites More sharing options...
Davie33 Posted May 19, 2012 Share Posted May 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262764-php-if-condition-not-working/#findComment-1346770 Share on other sites More sharing options...
Tenaciousmug Posted May 19, 2012 Author Share Posted May 19, 2012 Omg thank you everyone... I guess it's because I've been coding for the past 15 hours straight D: I was using my OOP functions wrong.. I forgot to put parantheses. I had $pet->set_color = $color when it should have been $pet->set_color($color); Quote Link to comment https://forums.phpfreaks.com/topic/262764-php-if-condition-not-working/#findComment-1346771 Share on other sites More sharing options...
Davie33 Posted May 19, 2012 Share Posted May 19, 2012 Cool glad u got it sorted . Quote Link to comment https://forums.phpfreaks.com/topic/262764-php-if-condition-not-working/#findComment-1346772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.