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 trialjohn paul
3,191 Pointscannot get task 3 to output
I got task 1- 3 correct , but I cannot understand why my code is task 3 wont output.
<?php
//edit this array
//$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
$contacts [] = [
'name' => 'Alena Holligan',
'email' => 'alena.holligan@teamtreehouse.com',
];
$contacts [] = [
'name' => 'Dave McFarland',
'email' => 'dave.mcfarland@teamtreehouse.com',
];
$contacts [] = [
'name' => 'Treasure Porth',
'email' => 'treasure.porth@teamtreehouse.com',
];
$contacts [] = [
'name' => 'Andrew Chalkley',
'email' => 'andrew.chalkley@teamtreehouse.com',
];
echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo "<li>$contacts[0]['name'] .': '. $contacts[0]['email']</li>\n";
echo "<li>$contacts[1]['name'] .': '. $contacts[1]['email']</li>\n";
echo "<li>$contacts[2]['name'] .': '. $contacts[2]['email']</li>\n";
echo "<li>$contacts[3]['name'] .': '. $contacts[3]['email']</li>\n";
echo "</ul>\n";
?>
/*
echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo "<li>Alena Holligan : alena.holligan@teamtreehouse.com</li>\n";
echo "<li>Dave McFarland : dave.mcfarland@teamtreehouse.com</li>\n";
echo "<li>Treasure Porth : treasure.porth@teamtreehouse.com</li>\n";
echo "<li>Andrew Chalkley : andrew.chalkley@teamtreehouse.com</li>\n";
echo "</ul>\n";
*/
5 Answers
Marwa Rashad
4,198 PointsHello John, I am sorry for the late reply. I am glad you worked it out. Let me tell you more of what I understand. Without concatenation, PHP will understand that the echo statement is ended after the double quotation marks ("<li>"). So it will find a variable alone without any context which will cause an error. Remember that concatenation is used to merge more than one string into one and echo() expects one string to echo, or two strings separated by a comma. Please check more about echo() in the documentation http://php.net/manual/en/function.echo.php. I hope this makes it clearer.
john paul
3,191 Pointsit does make more sense now, thank you !!
Marwa Rashad
4,198 PointsHi there! Itβs obviously a concatenation error. You have used the double quotation marks and the β.β as well on concatenation. You have to separate those parts. I suggest you revise the concatenation rules and try again. Remember you can always use curly braces with variables in case you need to save yourself the hustle. Finally, you will always find someone who asked the same question before you. Make sure you check the questions on the video before the challenge or the one after it to gain more insight. Happy coding!
john paul
3,191 PointsThanks Marwa, I will revisit concatentation. I did try and find if the question had been asked before. Obviously I did not try hard enough. Many thanks !!
Marwa Rashad
4,198 PointsAlways welcome! Good luck!
john paul
3,191 PointsHi, there is one thing I still do not understand Marwa, why we have to concatenate the array name $contacts[] after "<li>"
i.e. echo "<li>" . $contacts[0]['name'], ' : ' . $contacts[0]['email'] . "</li>\n";
john paul
3,191 PointsHi, it's ok,, I have worked it out... the code is only asking to print the tag name, there we need the double quotes and the concatenation.
Anamaria Costin
17,472 PointsAnamaria Costin
17,472 PointsHello,
There is a similar qustion answered, check the link https://teamtreehouse.com/community/replace-the-hard-coded-values-in-the-output-with-the-name-and-email-values-from-the-contacts-array.