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

I do not know what is wrong with my code.

I wrote what I think should be enough to complete this challenge, however I cannot complete it yet.

index.php
<?php

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

?>

2 Answers

Benjamin Payne
Benjamin Payne
8,142 Points

Hey Javier,

Check out this line:

if (in_array($color), $house->roof_color || in_array($color), $house->wall_color)

The closing parens should be after the array:

if (in_array($color, $house->roof_color) || in_array($color, $house->wall_color))

Let me know if that helps.

Thanks,

Ben

Thanks Benjamin, I tried your advice but it also did not work.

I could finally figure it out: the correct code is this:

<?php

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

?>