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

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.