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

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.