PHP PHP Arrays and Control Structures PHP Arrays Multidimensional Arrays

gabriel wambua
gabriel wambua
5,058 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 Staff

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,058 Points

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