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

arrays

I have tried to add an internal array but failed.Can someone please tell me what is wrong with this code

index.php
<?php
//edit this array
$contacts = array(
  'Alena' => array('name' => 'Alena Holligan'),
  'Dave' => array('name' => 'Dave McFarland'),
  'Treasure' => array('name' => 'Treasure Porth'),
  'Andrew' => array('name' => 'Andrew Chalkley')
);

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";
Lorenzo Leva
Lorenzo Leva
12,262 Points

Hi, so your error is that they ask for an array and not a dictionary (array is where the key is an int, a dictionary is where the key is a string). So you have to remove the key. So the right solution would be the following. If you have any other question please ask.

<?php
//edit this array
$contacts = array(
  array('name' => 'Alena Holligan'),
  array('name' => 'Dave McFarland'),
  array('name' => 'Treasure Porth'),
  array('name' => 'Andrew Chalkley')
);

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";

1 Answer

Great, it worked!!I am grateful for your help.

Lorenzo Leva
Lorenzo Leva
12,262 Points

My pleasure! Please rate the comment with the solution as best answer so I get credits and other people with your same problem find it better. have a nice day.