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 trialLeandro Roberto
3,574 PointsHow to return array object
I don't understand the question. the $this->houses array has another array of objects. How to check the wall_color and roof_color value and how to return this array?
<?php
// add code below this comment
class Subdivision
{
public $houses = array();
public function filterHouseColor($color)
{
foreach($this->houses as $house)
{
if ($house->roof_color == $color || $house->wall_color == $color)
{
return $house;
}
}
}
}
?>
Mark Miller
45,831 PointsMark Miller
45,831 PointsI'm stuck on this one also. But I see one mistakes in yours. You are returning only one match instead of continuing to loop through the entire array. The return statement terminates the for-each loop and exits the function immediately, so any remaining elements of the array go unchecked by your code. You should store each match in another array, then return that entire array of objects, the collection, after the for-each has checked them all.