What 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.
Jennifer NordellTreehouse Staff
Hi there! They are still concatenation. At the very beginning of the video, 0:00 you can see the associative array $items.
$item["img"] accesses this associative array and the value held there is a string. The same goes for
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 paul3,191 Points
Hi 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 !!!!