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 Shopping List Method

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Problem with Code sample in Teachers notes

Hi all,

I was wondering if Alena Holligan or somebody could clear up something for me.

I was able to reproduce the "cleaner ingredients" list for this video by following along the video without simply copying the code sample. So I looked at the code closely and I see that the code sample isn't the same as the version in the video.

So I commented out the version I made in my code and pasted this code sample into my project and it causes an error.

When I use the version of the method getCombinedIngredients I followed in the video the page works but the code sample produces the following error...

Parse error: syntax error, unexpected '}' in filepath\recipiecollection.php on line 144

Any ideas? What's the code sample for? What was it meant to do? Thanks :)

This is the code sample

//Code Sample from Teachers notes. 
       public function getCombinedIngredients()
        {
            $ingredients = array();
            foreach ($this->recipes as $recipe) {
                foreach ($recipe->getIngredients() as $i) {
                    $item = $i['item'];
                    if (strpos($item, ",")) {
                        $item = strstr($item, ",", true);
                    }
                    if (in_array($item . "s", $ingredient_list)) {
                        $item .= "s";
                    } else if (in_array(substr($ingredient,0,-1),$ingredient_list)) {
                        $ingredient = substr($ingredient,0,-1);
                    }
                    $ingredient_list[$item][] = array($i["amount"],$i["measure"]);
                }
            }
            return $ingredients.
        }
Alena Holligan
Alena Holligan
Treehouse Teacher

Thanks for finding thatJonathan Grieve! I must have copied the code from the wrong place :) I updated it now