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

Daniel Atonge
Daniel Atonge
4,769 Points

Assistance please !

Bummer! I do not see the use of the names from contacts array in the output. When calling the multidimensional array, you must first call the outer indexed array and then the inner associative array. Example: $array[#][STRING]

index.php
<?php
//edit this array

$contact[] = [
          'name' => 'Alena Holligan',
          'email' => 'alena.holligan@teamtreehouse.com',
];
$contact[] = [
          'name' => 'Dave McFarland',
          'email' => 'dave.mcfarland@teamtreehouse.com',
];
$contact[] = [
          'name' => 'Treasure Porth',
          'email' => 'treasure.porth@teamtreehouse.com',
];
$contact[] = [
          '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>$contact[0]['name'] : $contact[0]['email']</li>\n";
echo "<li>$contact[1]['name'] : $contact[1]['email']</li>\n";
echo "<li>$contact[2]['name'] : $contact[2]['email']</li>\n";
echo "<li>$contact[3]['name'] : $contact[3]['email']</li>\n";
echo "</ul>\n";

2 Answers

Hi Daniel,

Certain array variables have to be enclosed in curly braces if you want them to be evaluated inside double quotes.

Example: "<li>{$contact[0]['name']} : {$contact[0]['email']}</li>\n";

There is more information about that here: http://php.net/manual/en/language.types.string.php#language.types.string.parsing

Alternatively, you could use string concatenation to join each piece together.

Also, I don't know if this will affect the challenge but you changed the name of the variable from $contacts to $contact. That may need to be changed back if you're still not passing.

Jarren Bird
Jarren Bird
8,125 Points

Thanks Jason. I was struggling with the same problem, and your comment was just what I needed.

Also, thanks for asking the question, Daniel Atonge.