Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Object-Oriented PHP Basics!
You have completed Object-Oriented PHP Basics!
Preview
There's a lot more to a recipe then a title and source. In this video we'll be adding the rest of our property to the displayRecipe method, using a simple easy to read format.
Code Sample
public static function displayRecipe($recipe)
{
$output = "";
$output .= $recipe->getTitle() . " by " . $recipe->getSource();
$output .= "\n";
$output .= implode(", ",$recipe->getTags());
$output .= "\n\n";
foreach ($recipe->getIngredients() as $ing) {
$output .= $ing["amount"] . " " . $ing["measure"] . " " . $ing["item"];
$output .= "\n";
}
$output .= "\n";
$output .= implode("\n", $recipe->getInstructions());
$output .= "\n";
$output .= $recipe->getYield();
return $output;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
returns those to the function call
as a single formatted string.
0:00
The first thing we need to do is start an
output variable instead of returning this
0:00
line directly we're gonna add
that to the output variable.
0:04
We can then return our output variable.
0:16
We'll keep the title and
source as our first line.
0:23
Then we'll add a new line.
0:26
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up