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 trialAlexisca hall
23,683 PointsReturn an collection array of house objects whose public properties roof_color OR wall_color match the passed color para
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
class Subdivision {
public $houses = []; // Same thing as array()
public function filterHouseColor($color) {
$lots = []; // just a temporary array
// Looks like this is where you got lost
// In order to access the $houses array, you need to do $this->houses because $houses is a property on Subdivision
// This foreach loop loops through the $houses array
// So each cycle, $house contains a $house object found in $houses
foreach ($this->houses as $house) {
// Remember: you can only access $roof_color and $wall_color from the $house object
if ($house->roof_color === $color || $house->wall_color === $color) {
$lots[] = $house->lot; // Here, we append the value of each $house's $lot property to that temporary array up there named $lots
}
}
return $lots; // Finally, we return $lots
}
}
?>
1 Answer
Mikkel Rasmussen
31,772 PointsYou just need to change your append value in your if statement from $house->lot to just $house.
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsWhat is the problem you are running into? I am not very fluent in PHP so I can't help, but this will help others trying to solve your problem.