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 trial

PHP Object-Oriented PHP Basics Building a Collection Collection Objects

Return an array (Challenge 3 of 3 in Object Orientated Basics)

When I write challenge 1 and 2 the step is correct, but in the third step I can't understand because write appears "it look like task 1 is no longer passing. What's wrong? Thanks for reply.

index.php
<?php

// add code below this comment
class Subdivision {
public $houses = []; // Same thing as array()
  public function filterHouseColor($color) {
    $lots = array(); // just a te
    foreach (){
     if ( ) {
    // If true, add the House-&gt;lot property to the $lots array
    $lots[] = 
    }
  }
    return $lots;
  }
}
?>
Amitkumar Patel
Amitkumar Patel
6,699 Points

Hi Massimo,

This is the code that allowed me to pass this challenge:

<?php

class Subdivision { public $houses = [];

public function filterHouseColor($color) { $lots = []; //create array

foreach ($this->houses as $house) {  //loop through array

  if ($house->roof_color === $color || $house->wall_color === $color) {
    $lots[] = $house; 
  }
}

return $lots;  

} }

?>

Good luck!

1 Answer

Amitkumar Patel
Amitkumar Patel
6,699 Points

Hi Massimo,

This is the code that allowed me to pass this challenge:

<?php

class Subdivision { public $houses = [];

public function filterHouseColor($color) { $lots = []; //create array

foreach ($this->houses as $house) { //loop through array

if ($house->roof_color === $color || $house->wall_color === $color) { $lots[] = $house; } }

return $lots;
} }

?>

Good luck!