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

web master
web master
1,741 Points

is there a place to see the answers for each task?

unfortunately, the "bummer" suggestion just isn't helpful enough in this instance. I don't think that my code is semantically in error, but I'm clearly trying to do the wrong thing and comparing to the correct answer would be helpful.

index.php
<?php
//edit this array
$alena = array(
  'name' => 'Alena Holligan',
 );
$dave = array (
  'name' => 'Dave McFarland',
);
$treasure = array(
  'name' => 'Treasure Porth',
);
$andrew = array(
  'name' => 'Andrew Chalkley',
);
/*$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>Alena Holligan : alena.holligan@teamtreehouse.com</li>\n";
echo "<li>Dave McFarland : dave.mcfarland@teamtreehouse.com</li>\n";
echo "<li>Treasure Porth : treasure.porth@teamtreehouse.com</li>\n";
echo "<li>Andrew Chalkley : andrew.chalkley@teamtreehouse.com</li>\n";
echo "</ul>\n";

2 Answers

andren
andren
28,558 Points

Sadly there is not. You can usually find old forum posts for the challenge by searching for the challenge name plus the word Treehouse on Google though, which will often contain an example of how to solve the challenge.

As for your code, your commented out attempt is actually fine, you have just typed the wrong variable name, the array is supposed to be called contacts not contact.

If you fix that typo like this:

<?php
//edit this array
$contacts[] = [
  'name' => 'Alena Holligan',
  'email' => 'alena.holligan@teamtreehouse.com',
];
$contacts[] = [
  'name' => 'Dave McFarland',
  'email' => 'dave.mcfarland@teamtreehouse.com',
 ];
$contacts[] = [
  'name' => 'Treasure Porth',
  'email' => 'treasure.porth@teamtreehouse.com',
 ];
$contacts[] = [
  '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>Alena Holligan : alena.holligan@teamtreehouse.com</li>\n";
echo "<li>Dave McFarland : dave.mcfarland@teamtreehouse.com</li>\n";
echo "<li>Treasure Porth : treasure.porth@teamtreehouse.com</li>\n";
echo "<li>Andrew Chalkley : andrew.chalkley@teamtreehouse.com</li>\n";
echo "</ul>\n";

Then you will be able to pass the first task.

web master
web master
1,741 Points

Perfect. Thanks.

Anthony Meyer
Anthony Meyer
2,472 Points

You can usually find the answer by copying and pasting the challenge instructions in the "Get Help" dialog box that pops up after clicking the "Get Help" box.

web master
web master
1,741 Points

Thanks. I'll do that next time.