Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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;
  }


}
?>