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 trialYousif Sayer
7,073 PointsPlease need help in this challenge
<?php
//edit this array
//$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
$contacts = array(array(
'Alena Holligan' => 'alena.holligan@teamtreehouse.com',
'Dave McFarland' => 'dave.mcfarland@teamtreehouse.com',
'Treasure Porth' => 'treasure.porth@teamtreehouse.com',
'Andrew Chalkley' => 'andrew.chalkley@teamtreehouse.com',
));
echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo "<li>$contacts[0]['Alena Holligan']</li>\n";
echo "<li>$contacts[0]['Dave McFarland']</li>\n";
echo "<li>$contacts[0]['Treasure Porth']</li>\n";
echo "<li>$contacts[0]['Andrew Chalkley']</li>\n";
echo "</ul>\n";
<?php
//edit this array
//$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
$contacts = array(array(
'Alena Holligan' => 'alena.holligan@teamtreehouse.com',
'Dave McFarland' => 'dave.mcfarland@teamtreehouse.com',
'Treasure Porth' => 'treasure.porth@teamtreehouse.com',
'Andrew Chalkley' => 'andrew.chalkley@teamtreehouse.com',
));
echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo "<li>$contacts[0]['Alena Holligan']</li>\n";
echo "<li>$contacts[0]['Dave McFarland']</li>\n";
echo "<li>$contacts[0]['Treasure Porth']</li>\n";
echo "<li>$contacts[0]['Andrew Chalkley']</li>\n";
echo "</ul>\n";
/*
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"
*/
4 Answers
Yousif Sayer
7,073 PointsI'm stuck with this challenge!
Yousif Sayer
7,073 PointsI tried this code and no luck
<?php //edit this array //$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley'); $contacts["Alena"]=[ "name" => "Alena Holligans", "email" => "alena.holligan@teamtreehouse.com" ];
$contacts["Dave"]=[ "name" => "Dave McFarland", "email" => "dave.mcfarland@teamtreehouse.com" ];
$contacts["Treasure"]=[ "name" => "Treasure Porth", "email" => "treasure.porth@teamtreehouse.com" ];
$contacts["Andrew"]=[ "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["Alena"]["name"] . " : " . $contacts["Alena"]["email"] . "</li>\n"; echo "<li>" . $contacts["Dave"]["name"] . " : " . $contacts["Dave"]["email"] . "</li>\n"; echo "<li>" . $contacts["Treasure"]["name"] . " : " . $contacts["Treasure"]["email"] . "</li>\n"; echo "<li>" . $contacts["Andrew"]["name"] . " : " . $contacts["Andrew"]["email"] . "</li>\n"; echo "</ul>\n"; ?>
jason chan
31,009 Points//Try these are associative arrays
<?php
$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'),
);
// . . .
//And after that replace hardcoded text with data from array:
<?php
// . . .
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";
Yousif Sayer
7,073 PointsThanks for the help, it still doesn’t work. This the challenge that I'm trying with
In the code below, we have a simple array of contact names. We want to use the $contacts array to fill in the hardcoded list of names an email addresses. To hold the email as well as the name for each contact, we need a multidimensional array, meaning each person in the contact list will have their own array. The first step is to make each person their own single item ASSOCIATIVE array, using 'name' as the key for these internal arrays.
Austin Whipple
29,725 PointsAustin Whipple
29,725 PointsCleaned up your code samples a bit!