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

Tim Windhorst
Tim Windhorst
8,242 Points

In the code below, we have a simple array of contact names. We want to use the $contacts array to fill in the hardcoded

Hey friends,

I feel like I've got this right but I receive the error: "Bummer! I do not see the required output. You should not be modifying the output at this point."

Please have a look:

<?php
//edit this array
$contacts = array(
  array('Alena Holligan','alena.holligan@teamtreehouse.com'),
  array('Dave McFarland','dave.mcfarland@teamtreehouse.com'),
  array('Treasure Porth','treasure.porth@teamtreehouse.com'),
  array('Andrew Chalkley','andrew.chalkley@teamtreehouse.com')
);
echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo $contacts[0][0] . " : " . $contacts[0][1] . "<br />\n";
echo $contacts[1][0] . " : " . $contacts[1][1] . "<br />\n";
echo $contacts[2][0] . " : " . $contacts[2][1] . "<br />\n";
echo $contacts[3][0] . " : " . $contacts[3][1] . "<br />\n";
echo "</ul>\n";

2 Answers

I would recommend also adding string keys instead of using numbers. So adding

 'name'=>'Alena Holligan','email'=>'alena.holligan@teamtreehouse.com' 

within the array allows you to reference it by the keys of name and also by email instead of [0][0] and [0][1].

Hmmm... the parsers seems to be a bit pick about spacing, I noticed. I think that is what they are looking for. This seemed to work for me below.

<?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";
Tim Windhorst
Tim Windhorst
8,242 Points

Thank you. You set me down the right path, the solution was both using string keys and list item tags.

Awesome, glad that helped you out and worked.