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

Claudio Vendrame
Claudio Vendrame
4,964 Points

Here we go "stuck again":)

The code gives the right display, I guess .

For the experts out there: What could be wrong?

Thanks for the help.

index.php
<?php
//edit this array
$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
$contacts = array
  (
  array('Alena Holligan','alena.holligan@teamtreehouse.com'),
  array('Dave McFarland','dave.mcfarland@teamtreehouse.com'),
  array('Treasure Porth','treasure.porth@teamtreehouse.com'),
  array('Andrew Chalkley','andrew.chalkley@teamtreehouse.com')
);
echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo "<li>" . $contacts[0][0] . " :" . $contacts[0][1]."</li>\n";
echo "<li>".$contacts[1][0] . " :" . $contacts[1][1]."</li>\n";
echo "<li>".$contacts[2][0] . " :" . $contacts[2][1]."</li>\n";
echo "<li>".$contacts[3][0] . " :" . $contacts[3][1]."</li>\n";
echo "</ul>\n";

3 Answers

Thomas Dimnet
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Thomas Dimnet
Python Development Techdegree Graduate 43,629 Points

Hi,

I do not understand: where are you stuck? I put your code on my computer and it displays me a list of name and e-mail. Do you want to optimize your code?

Cheers. Thomas.

Claudio Vendrame
Claudio Vendrame
4,964 Points

Hi! That is what I don't understand. In the lesson it tells me to display a list of contacts and email of each individual where each individual has its own array. But I get a message telling me that the output is not correct. Perhaps I didn't understand the task properly. That is what I want a help with.

Sorry for not being clear. I am just trying to get use to it.

Thank you very much.

Thomas Dimnet
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Thomas Dimnet
Python Development Techdegree Graduate 43,629 Points

Ok, understood (I looked at the challenge ^^).

So, you have to set 'name' as the key value of your multidimensional array. The syntax for this is quite simple:

$yourArray = [
  [
    'name' => 'value'
  ]
];

You can go on php.net to find a great peace of ressources :) => multi array

And the solution of your first step:

$contacts = array(
  ['name' => 'Alena Holligan'], 
  ['name' => 'Dave McFarland'], 
  ['name' => 'Treasure Porth'], 
  ['name' => 'Andrew Chalkley']
);
Claudio Vendrame
Claudio Vendrame
4,964 Points

Shame on me. You are right, it is quite simple and embarrassing. Unfortunately it seems to be just the beginning of a pile of simple mistakes.

Thank you for your passions and help.