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 trialBen Salem
796 PointsHi! i really dont know where is my mistake here, as i did what is written in the task:
please redirect me to the right way and show me my mistakes.
<?php
//edit this array
//$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
$contacts[name] = [
'Name' => 'Alena Holligan',
'Email' => 'alena.holligan@teamtreehouse.com',
];
$contacts[name] = [
'Name' => 'Dave McFarland',
'Email' => 'dave.mcfarland@teamtreehouse.com',
];
$contacts[name] = [
'Name' => 'Treasure Porth',
'Email' => 'treasure.porth@teamtreehouse.com',
];
$contacts[name] = [
'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>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";
2 Answers
Adam Pengh
29,881 PointsBreaking this down into the multiple steps:
Step 1. Convert each person to their own associate array with 'name' as the key
<?php
//edit this array
$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
// Step 1. Convert each person to their own associate array with 'name' as the key
$contacts = array(
array('name' => 'Alena Holligan'),
array('name' => 'Dave McFarland'),
array('name' => 'Treasure Porth'),
array('name' => 'Andrew Chalkley')
);
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";
Step 2. Add a second element with the key 'email' to the internal array of each person
<?php
//edit this array
$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
// Step 2. Add a second element with the key 'email' to the internal array of each person
$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>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";
Step 3: Replace the hard coded values in the output with the name and email values from the contacts array.
<?php
//edit this array
$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
// 3. Replace the hard coded values in the output with the name and email values from the contacts 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";
John Raymond Abella
3,598 PointsThanks to this question and the answer provided, I was able to get past the step 3. I didn't think of concatenating them together :O
Ben Salem
796 PointsThanks a lot for the detailed answer, i had it all wrong! gotta practice more.... i had a look into your profile, pretty impressive. Thanks again :)
Ben Salem
796 PointsBen Salem
796 Pointsbtw it didnt work even with my first try that it was lik the following code: