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 trialGyörgy Varga
19,198 PointsDon't understand this part...
Hi!
Can you please help me understand this part:
<?php
public function getCombinedIngredients()
{
$ingredients = array();
foreach ($this->recipes as $recipe) {
foreach ($recipe->getIngredients() as $ing) {
$item = $ing["item"];
if (strpos($item, ",")) {
$item = strstr($item, ",", true);
}
if (in_array($item."s", $ingredients)) {
$item.="s";
} else if (in_array(substr($item, 0, -1), $ingredients)) {
$item = substr($item, 0, -1);
}
$ingredients[$item] = array(
$ing["amount"],
$ing["measure"]
);
}
}
return $ingredients;
}
If at the end we add the "amount" and "measure" why it does not display it? Thanks for your help!
Robert Leonardi
17,151 PointsRobert Leonardi
17,151 PointsCan you provide the sample output array of $this->recipes and $recipe->getIngredients() ?