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

Moritz Laube
Moritz Laube
6,989 Points

OOP Filtering for $color

Hi! I am struggling with the 3rd task in the code-along within the collection class section Here I have to filter for the $color variable.

This is my solution:

class Subdivision { public $houses = array(); public function filterHouseColor($color) { foreach ($this->houses as $house) { if (in_array($color, $house->roof_color) || in_array($color, $house->wall_color)) { $houses[] = $house; } } return $this->houses; }

}

But it keeps saying: Make sure you are filtering for $color … 

Can you please help?

Thanks in advance

index.php
<?php

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


}
?>