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 trialStephen Limmex
32,604 PointsStuck on challenge task 3 - you should not be modifying the output at this point
I am stuck on challenge task 3. I have been working on this for some time and started over a few times; however I continue to eventually get an error message stating 'I do not see the required output, you should not be modifying the output at this point.'
Rather than continue to walk into this wall headfirst and get frustrated I am asking for help. Please advise why I am getting the error message.
Thank you, Steve
<?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 "<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";
Joel Bardsley
31,249 PointsHi Steve,
Just to add to the answers provided that the error is caused by attempting to echo an array item as a string. If you tried to do this on your own site you'd get a PHP notice "NOTICE Array to string conversion..." appearing on-screen, so concatenation is required in this case.
Hope that helps, Joel
Jason Anello
Courses Plus Student 94,610 PointsYou can have array items in double quotes but they have to be enclosed in curly braces.
echo "<li>{$contacts[0]['name']} : {$contacts[0]['email']}</li>\n";
3 Answers
Juan Ignacio Lambardi
3,943 Points<?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 "<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";
?>
Eric Drake
6,339 PointsI just ran through the challenge that you are working on. The code validator in the quiz doesn't like how you've included your variables inside the double-quotes. I changed my answer to include the snippet below, and it worked.
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";
Juan Ignacio Lambardi
3,943 PointsAnd remember adding "<li>" "</li>\n". You're typing "<li$contacts......" that it won't work! :)
Juan Ignacio Lambardi
3,943 PointsJuan Ignacio Lambardi
3,943 PointsHi Stephen!, you're missing insert doble quotes between the ":" and the "." to combine the hole sentence. Check with this code if it works! :)