Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Object-Oriented PHP Basics Building a Collection Collection Objects

How to return an collection array of house objects that match the passed color parameter.

This is bit confusing because i don't know why it's not working. I'm getting each house and then compare the walls/roofs with the passed color. If it's true it adds the house to the output array.


// add code below this comment
class Subdivision
  public $output = array();
    public $houses = array();
  public function filterHouseColor($color)
    foreach ($this->houses as $house){
      if($this->roof_color === $color || $this->wall_color === $color){
        $this->output[] = $house;
    return $this->output;


This part here was wrong:

if($this->roof_color === $color || $this->wall_color === $color){

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there, Damian Toczek ! You're doing terrific and you're super close! Take a look at this line:

foreach ($this->houses as $house)

This is set up just fine. But it also means that for every iteration through that collection, the individual item is assigned to the variable $house. Then in the very next line, you set up your if statement just brilliantly, but you're comparing the roof_color and wall_color of this. You should be comparing the roof_color and wall_color of the $house.

Making that change will cause this to pass. Hope this helps! :sparkles:

Hi, thank you, I've already noticed that.