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

Alex Bauer
Alex Bauer
9,426 Points

Can someone help me with a public function please?

The error that I received tells me that I need to return an array.

These are the instructions: Return an collection array of house objects whose public properties roof_color OR wall_color match the passed color parameter.

Note: The local houses array contains an array of House objects, each of which has a public property for "roof_color" and "wall_color".

index.php
<?php

// add code below this comment
class Subdivision
{
        public $houses;

    public function filterHouseColor($color)
    {
        $house = array();
            if ($this->houses["roof_color"] == $color OR $this->houses["wall_color"] == $color) {
                $house[] = $color;
          return $house;
        }
    }
}

?>
Alex Bauer
Alex Bauer
9,426 Points

I used the logical operator OR because it seemed like the instruction emphasized on it.

jamesjones21
jamesjones21
9,260 Points

I believe you need to declare the keys inside the array for them to be noticed inside the foreach loop. As the conditions set will bring back nothing as it can't compare anything with a blank array.

1 Answer

Patrick Marshall
Patrick Marshall
13,508 Points

$houses is an array. You need a foreach loop to check each house in the array.

Alex Bauer
Alex Bauer
9,426 Points

Oh okay ty so much for your help!