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 trial

PHP PHP Arrays and Control Structures PHP Arrays Multidimensional Arrays

Taylor Schimek
Taylor Schimek
19,318 Points

bugged challenge

Challenge 3 after Multidimensional Array video seems to be bugged. The task is : "Replace the hard coded values in the output with the name and email values from the contacts array."

when i do that (preview shows it's correct), the Check Work returns this comment: "Bummer! I do not see the required output. You should not be modifying the output at this point."

index.php
<?php
//edit this array
$contacts = array(['name' => 'Alena Holligan'], 
                  ['name' => 'Dave McFarland'], 
                  ['name' => 'Treasure Porth'], 
                  ['name' => 'Andrew Chalkley']);
$contacts[0]['email'] = 'alena.holligan@teamtreehouse.com';
$contacts[1]['email'] = 'dave.mcfarland@teamtreehouse.com';
$contacts[2]['email'] = 'treasure.porth@teamtreehouse.com';
$contacts[3]['email'] = 'andrew.chalkley@teamtreehouse.com';

echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo "<li>";
echo $contacts[0]['name'] . ' : ' . $contacts[0]['email']; 
echo "</li>";
echo "<li>";
echo $contacts[1]['name'] . ' : ' . $contacts[1]['email'];
echo "</li>";
echo "<li>";
echo $contacts[2]['name'] . ' : ' . $contacts[2]['email'];
echo "</li>";
echo "<li>";
echo $contacts[3]['name'] . ' : ' . $contacts[3]['email'];
echo "</li>";
echo "</ul>\n";

2 Answers

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

Challenge should be updated to accept that answer

While your solution would technically work there is a much cleaner implementation that they are looking for. But you are so very close to having it right!

$contacts = array(['name' => 'Alena Holligan'], 
                  ['name' => 'Dave McFarland'], 
                  ['name' => 'Treasure Porth'], 
                  ['name' => 'Andrew Chalkley']);
$contacts[0]['email'] = 'alena.holligan@teamtreehouse.com';
$contacts[1]['email'] = 'dave.mcfarland@teamtreehouse.com';
$contacts[2]['email'] = 'treasure.porth@teamtreehouse.com';
$contacts[3]['email'] = 'andrew.chalkley@teamtreehouse.com';

becomes:

$contacts = array(
    ['name' => 'Alena Holligan', 'email' => 'alena.holligan@teamtreehouse.com'], 
    ['name' => 'Dave McFarland', 'email' => 'dave.mcfarland@teamtreehouse.com'], 
    ['name' => 'Treasure Porth', 'email' => 'treasure.porth@teamtreehouse.com'], 
    ['name' => 'Andrew Chalkley', 'email' => 'andrew.chalkley@teamtreehouse.com']
);