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

Amitkumar Patel
Amitkumar Patel
6,699 Points

Return an collection array of house objects whose public properties roof_color OR wall_color match the passed color para

This is the error message I get:

Bummer! Make sure you are checking both the "roof_color" AND "wall_color" to see if EITHER of them match the passed $color parameter.

Can someone assist me please? I would be very thankful.

index.php
<?php
class Subdivision {
  public $houses = []; 
  public function filterHouseColor($color) {
    $lots = $house; 

     foreach ($this->house as $house) {

      if ($house->roof_color == $color || $house->wall_color == $color) {
        $lots[] = $house->lots;
      }
    }

    return []; 
  }
}
?>
Amitkumar Patel
Amitkumar Patel
6,699 Points

Please anyone? It's the final challenge 3/3 out of the collections object challenge.

1 Answer

Mochammad Rezza
Mochammad Rezza
4,778 Points

Hii Amitkumar,

let's try this code

<?php

// add code below this comment
class Subdivision
{
  public $houses = [];
  public $arr = [];

  public function filterHouseColor($color)
  {
    foreach($this->houses as $house){
      if($house->roof_color == $color OR $house->wall_color == $color){
        $this->arr[] = $house;
      }
    }
    return $this->arr;
  }
}
?>
Amitkumar Patel
Amitkumar Patel
6,699 Points

Hi Mochammad,

Thank you for your assistance, however I've figured it out and passed this challenge.

Thanks anyway!