Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Arrays and Control Structures PHP Arrays Multidimensional Arrays

multidimensional arrays - challenge task 1 of 3 working but not correct ?

This is my code to achieve the task. It works but is called incorrect. Can you give me an example of how this task is to be achieved using an array for each individual?

$contacts['name'][0] = 'Alena Holligan'; $contacts['name'][1] = 'Dave McFarland'; $contacts['name'][2] = 'Treasure Porth'; $contacts['name'][3] = 'Andrew Chalkley';

$contacts['email'][0] = 'alena.holligan@teamtreehouse.com'; $contacts['email'][1] = 'dave.mcfarland@teamtreehouse.com'; $contacts['email'][2] = 'treasure.porth@teamtreehouse.com'; $contacts['email'][3] = 'andrew.chalkley@teamtreehouse.com';

echo "<ul>\n"; echo '<li>'; echo $contacts['name'][0]; echo ' : '; echo $contacts['email'][0]; echo "</li>\n";

echo '<li>'; echo $contacts['name'][1]; echo ' : '; echo $contacts['email'][1]; echo "</li>\n";

echo '<li>'; echo $contacts['name'][2]; echo ' : '; echo $contacts['email'][2]; echo "</li>\n";

echo '<li>'; echo $contacts['name'][3]; echo ' : '; echo $contacts['email'][3]; echo "</li>\n";

echo "</ul>\n";

index.php
<?php
//edit this array
$contacts['name'][0] = 'Alena Holligan';
$contacts['name'][1] = 'Dave McFarland';
$contacts['name'][2] =  'Treasure Porth';
$contacts['name'][3] = 'Andrew Chalkley';

$contacts['email'][0] = 'alena.holligan@teamtreehouse.com';
$contacts['email'][1] = 'dave.mcfarland@teamtreehouse.com';
$contacts['email'][2] = 'treasure.porth@teamtreehouse.com';
$contacts['email'][3] = 'andrew.chalkley@teamtreehouse.com';

echo "<ul>\n";
echo '<li>';
echo $contacts['name'][0];
echo ' : ';
echo $contacts['email'][0];
echo "</li>\n";


echo '<li>';
echo $contacts['name'][1];
echo ' : ';
echo $contacts['email'][1];
echo "</li>\n";

echo '<li>';
echo $contacts['name'][2];
echo ' : ';
echo $contacts['email'][2];
echo "</li>\n";

echo '<li>';
echo $contacts['name'][3];
echo ' : ';
echo $contacts['email'][3];
echo "</li>\n";


echo "</ul>\n";

1 Answer

I understand it now. My answer would in effect be the same as making 2 separate arrays, like this.: (rather than an array for each person) $contacted['name'] = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley'); $contacted['email'] = array('alena.holligan@teamtreehouse.com', 'dave.mcfarland@teamtreehouse.com', 'treasure.porth@teamtreehouse.com', 'andrew.chalkley@teamtreehouse.com'); Though it works to solve the challenge,I guess the downside of this could be what happens to one array if you change the other.