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 trialAlex Bauer
9,426 PointsCan 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".
<?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;
}
}
}
?>
jamesjones21
9,260 PointsI 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
13,508 Points$houses is an array. You need a foreach loop to check each house in the array.
Alex Bauer
9,426 PointsOh okay ty so much for your help!
Alex Bauer
9,426 PointsAlex Bauer
9,426 PointsI used the logical operator OR because it seemed like the instruction emphasized on it.