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

I don't understand the correction statement. To display this in PHP, is my associative array to be called or imploded?

When I call the array, the PHP converter says error, and that it should be converted to a string (as I expect). So in order to convert it to a string, I implode the array to display it.

The output seems to match what is required. However when I implode it, I get a correction statement saying it doesn't see the correct output and that the array should just be called. I've tried different ways but I seem to get conflicting statements between the PHP converter and the correction statement.

I'm feel I understand arrays pretty well, but I can't seem to get past this lesson. I'm new to this, so there could be something I'm overlooking or overthinking. Please help.

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

echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.

$contact1 = implode(" : ", $contacts[0]);
$contact2 = implode(" : ", $contacts[1]);
$contact3 = implode(" : ", $contacts[2]);
$contact4 = implode(" : ", $contacts[3]);

echo "<li>$contact1</li>\n";
echo "<li>$contact2</li>\n";
echo "<li>$contact3</li>\n";
echo "<li>$contact4</li>\n";

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hey Don, the question is this case specifically wants you to access the array elements to generate the output (use $contacts[index]['name'] and $contacts[index]['email'].