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

Jack Cooper
Jack Cooper
5,557 Points

Collection Objects task 3 of 3: Filtered objects returning correct objects. Not sure why I can not continue.

I've created my filter and it appears to be working when I var_dump.

The color is blue, there are three houses: Lot A, B and C. Lot A has a blue roof and Lot B has a blue wall (it may be the other way around).

But lot C is white and red and is not returned in my array which is what It asked for. so I'm unsure as to what I've done wrong.

Any Help is appreciated.

Many Thanks, Jack

index.php
<?php

// add code below this comment
class Subdivision
{
  public $houses = array();

  public function filterHouseColor($color)
  {
    $taggedRecipes = array();
        foreach ($this->houses as $house) {
          //var_dump($house);
            if(strtolower($color) == $house->wall_color){
                $filteredHouses[] = $house;
            }
        }
        foreach ($this->houses as $house) {
            if(strtolower($color) == $house->roof_color){
                $filteredHouses[] = $house;
            }
        }
        //var_dump($color);
        var_dump($filteredHouses);
        return $filteredHouses;
  }
}
?>

1 Answer

Jack Cooper
Jack Cooper
5,557 Points

I worked it out. I needed to combine the two loops and use an OR like the question asked. My bad.