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 trialNoah Auerhahn
3,628 PointsThis is the error I'm getting: Uncaught Error: Cannot use object of type House as array in index.php:13
Appreciate help.
<?php
// add code below this comment
class Subdivision {
public $houses = array();
public function filterHouseColor($color)
{
$filteredHouses = array();
foreach($this->houses as $house){
if($house["wall_color"] == $color || $house["roof_color"] == $color){
$filteredHouses[] = $house[$color];
}
}
return $filteredHouses;
}
}
?>
1 Answer
Brian Jensen
Treehouse StaffCheck out this solution by Mochammad Rezza here -> view solution
I have pasted it with syntax highlighting for your convenience:
<?php
// add code below this comment
class Subdivision
{
public $houses = [];
public $arr = [];
public function filterHouseColor($color)
{
foreach($this->houses as $house){
if($house->roof_color == $color OR $house->wall_color == $color){
$this->arr[] = $house;
}
}
return $this->arr;
}
}
?>