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 trialHugo Zaanen
11,897 Pointscontacts array
I can't figure out why my code isn't working, thanks
<?php
//edit this array
$contacts = array( array('name' => 'Alena Holligan', 'email' => 'alena.holligan@teamtreehouse.com')
, array('name' => 'Dave McFarland', 'email' => 'dave.mcfarland@teamtreehouse.com')
, array('name' => 'Treasure Porth', 'email' => 'treasure.porth@teamtreehouse.com')
, array('name' => 'Andrew Chalkley','email' => 'andrew.chalkley@teamtreehouse.com')
);
echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo $contacts[0]['name'] . " " . $contacts[0]['email'] . "\t";
echo $contacts[1]['name'] . " " . $contacts[1]['email'] . "\t";
echo $contacts[2]['name'] . " " . $contacts[2]['email'] . "\t";
echo $contacts[3]['name'] . " " . $contacts[3]['email'] . "\t";
echo "</ul>\n";
2 Answers
Algirdas Lalys
9,389 PointsHi Hugo Zaanen
multidimensional array seems to be fine, but what I think what is missing is <li> elements, I think the challenge expects different output. For example.
<?php
echo "<li>" . $contacts[0]['name'] . " : " . $contacts[0]['email'] . "</li>\n";
// and all the rest of the contacts
?>
Riban Ulrich
110,728 PointsIf you look at the formatting from the original code, the name and email were rendered with a : separating them.
echo "<li>Alena Holligan : alena.holligan@teamtreehouse.com</li>\n";
I believe you need to copy that formatting to complete the task.
echo "<li>" . $contacts[0]['name'] . " : " . $contacts[0]['email'] . "</li>\n";
Algirdas Lalys
9,389 PointsAlgirdas Lalys
9,389 PointsYes if you checked in 'preview' It might look like same result, but for example if you wanted to use CSS on your <li> elements change the look of your contact form, it would be advantage. On the other hand this challenge expects <li> elements.