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

How do I output strings from the arrays to the hard code at the bottom?

I've managed to go through step 1 and 2 – creating a multidimensional array ('$contacts') with 'name' and 'email' as keys in the array.

The 3rd step is to replace the hard code at the bottom so that the array can feed into it. I've been trying for the past few days and can't get my head around it.

Any ideas where I'm going wrong? I've tried to concatenate the '$contact' variable into the echo statement. When I go to 'Check Work' it tells me that I shouldn't be doing any changes to the output code at this point. I'm confused!

Thanks

index.php
<?php
//edit this array
$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.
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";

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! First, you're doing fantastic! Good work on understanding multidimensional arrays. This particular Bummer! message on stage 3 is a bit misleading. Yes, you should be changing the output. However, your string for the second, third, and fourth people aren't exactly correct. They contain an extra space before the colon.

Notice in your code how the colons do not line up, but they should. They should be in exactly the same place as the one that displays $contacts[0]. In the following lines, instead of writing a space, colon, and then a space, you wrote two spaces, a colon, and then a space. In the latter version, there are two spaces before the colon which is what is causing the output to not match.

Hope this helps! :sparkles:

Woohoo! Thanks Jennifer! You just helped me earn my PHP Arrays Badge.

It's typical isn't it? It's the smallest thing with code. Didn't realise the colon spacing was off. I was racking my brains with this for ages.

Thanks ever so much.