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 trialrandolphelliot
1,716 PointsTask 2 not working. Not passing information from Task 1
Task 2 not working. Not passing values
<?php
class Render {
protected $size = array("length", "width");
public static function displayDimensions($size)
{
foreach ($size as $X) {
$output = $X["length"] . " X " . $X["width"];
}
return $output;
}
?>
2 Answers
Aaron Loften
12,864 PointsHey. I found out the problem. It took me a minute because I did the same thing as you. I assumed that by "passing an array containing length and width" it meant an object with a key:value pair but it does not.
My php is a bit rusty so forgive my syntax if its a little off. The answer is solid, I tested it. :)
In case you dont know the difference... An array contains just values. Basically you can set $size = array(1, 2, "your momma"). Note - some languages allow you to include objects as values here but lets ignore this as to not cause confusion. An object has a key:value pair setup. Basically, you can set $size = array("length" => 1, "width"=> 2, "my honey"=>"your momma") .
So...the following works because its searching an array, rather than an object. Also, I think yours is using a capital "x" instead of a lowercase "x."
<?php
class Render {
public static function displayDimensions($size) {
return $size[0] . " x " . $size[1];
}
}
?>
Also, I think my terminology is off. object = associative array...maybe. Idc....its all the same, just different languages with a more confusing way to say the same thing. :p
randolphelliot
1,716 Pointsthat worked. Thanks for the explanation!!