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

gabriel wambua
gabriel wambua
5,061 Points

What am I doing wrong?

I felt for sure that this code would work. I am however getting an error telling me that there should only be 2 levels of arrays. The main array and 4 other arrays set inside the main array.

The code looks sound. What am I doing wrong?

index.php
<?php


$contacts[0] = array(
  "alena"=>array(
  'name'=> 'Alena Holigan',
  'email'=>'alena.holligan@teamtreehouse.com'
),

  "dave"=>array(
  'name'=> 'Dave McFarland',
  'email'=>'dave.mcfarland@teamtreehouse.com'
),

  "Treasure"=>array(
  'name'=> 'Treasure Porth',
  'email'=>'treasure.porth@teamtreehouse.com'
),

  "Andrew"=>array(
  'name'=> 'Andrew Chalkle',
  'email'=>'andrew.chalkley@teamtreehouse.com'
));

1 Answer

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

Hi there, gabriel wambua ! Looks like you're off to a terrific start, but that's not quite what they're asking for. First, you are assigning everything to the 0 index of $contacts, but each index of $contacts should be an array. Secondly, you're providing a key that isn't being asked for. Third, on Andrew Chalkley's name you have a misspelling of their name and also on Alena Holligan. Let's take a look at how I might start that array, which is actually very similar to your code:

<?php


$contacts = array(
  array(
  'name'=> 'Alena Holligan',
  'email'=>'alena.holligan@teamtreehouse.com'
),

Continue in this pattern, but check again the spelling of "Alena Holigan" which is what you have vs "Alena Holligan" and "Andrew Chalkle" (your version) and "Andrew Chalkley" (the correct spelling).

Hope this helps! :sparkles:

gabriel wambua
gabriel wambua
5,061 Points

Wow.....I really didn't see the spelling errors there. Thanks this has helped me crack the challenge. !