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!
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
Concatenation of the working variables. Why?
Can someone explain why there needs to be concatenation on each side of the working variable? What purpose does it serve?
Why won't this work?
echo '<img src="'$product["img"]'" alt="'$product["name"]'"';
Just curious. Thanks!
Chris Shaw26,676 Points
Your current code is almost correct, after the opening single quote and before the ending single quote you need a period which tells the PHP compiler that you're joining two strings together, see the below.
NOTE: I've also added an ending closing bracket for the
echo '<img src="' . $product["img"] . '" alt="' . $product["name"] . '">';
Now your code should work without any issues.