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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![David Choi](https://uploads.teamtreehouse.com/production/profile-photos/448902/micro_10473200_511263875673299_7593609633151141548_n__1_.jpg)
David Choi
8,536 PointsWhat are the periods in image source for?
In the video, Alena writes the code:
echo "<li><a href='#'><img src= '"
. $item["img"] . "' alt='"
. $item["title"] . "' />"
What is the purpose of the periods in this case? Normally, they are used to join two strings together, but I'm not sure what strings are being joined together.
2 Answers
![Jennifer Nordell](https://uploads.teamtreehouse.com/production/profile-photos/5432702/micro_jen-square.jpg)
Jennifer Nordell
Treehouse TeacherHi there! They are still concatenation. At the very beginning of the video, 0:00 you can see the associative array $items.
The $item["img"]
accesses this associative array and the value held there is a string. The same goes for $img["title"]
.
The result of this will be that this line will be echoed out onto the DOM:
<li><a href='#'><img src= 'img/media/design_patterns.jpg' alt="A Design Patterns: Elements of Reusable Object-Oriented Software" />
On a side note, she goes on to close the anchor tag and make a paragraph. But yes, the dots are simply concatenation.
Hope this helps!
![john paul](https://secure.gravatar.com/avatar/d9f68e18943d66d5f02b6d5ede21c90e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
john paul
3,191 PointsHi Jennifer, just came across your post in the forum. I was really struggling with this problem myself, right from the start of the PHP beginners training, as there was never any explanation of why we use the period in these situations. Your explanation was perfect and now I get it !! Many thanks !!!!
John
David Choi
8,536 PointsDavid Choi
8,536 PointsThank you for your answer! However, I am still confused about what strings are being joined together. The normal example I know is:
In the code in the video, I'm not entirely too sure what strings are being joined together. I guess I'm not familiar with the periods being inside the quotations.
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherHi again! Ok so let's take a closer look. In the
catalog.php
you have this:This bit of code goes through each
$catalog
in the list and turns it into an $item and prints it out as a list item. So far so good? Now let's take a look at a$catalog
. You can find all the catalog entries in thedata.php
, but let's take a look at just one of them.Now since we've set a single catalog to have a local variable name of
$item
for the entire execution of the loop we can access the associative array inside just as we would any other associative array. As you can see most of the values are strings with a few exceptions. The value for"authors"
is yet another array of strings and the value of"year"
is an integer.When we type
$item["img"]
we are accessing that array and getting the value that resides there. In this case, the value is the string "img/media/design_patterns.jpg". The same is true for $item["title"]. The value stored there is also a string of "A Design Patterns: Elements of Reusable Object-Oriented Software".I took the liberty of making an example all done in one file which might illustrate the point a little better. Please feel free to run this in a workspace and check out the results. Maybe it will make a bit more sense then.
Hope this helps clarify things!![:sparkles: :sparkles:](https://image-proxy-cdn.teamtreehouse.com/6bdf233d70e10f861f7e4f3b6d6fcb7b924688b0/68747470733a2f2f7374617469632e7465616d74726565686f7573652e636f6d2f696d616765732f656d6f6a692f756e69636f64652f323732382e706e67)