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

travis brown
travis brown
1,292 Points

whats wrong with my code, php

Add a second element with the key 'email' to the internal array of each person. You'll find the correct email for each person in the hard coded output.

this is the second part of the quiz. here is my code, it says there is only a single element for alena holligan. am i not adding a second element to each? what am i missing, or am i misunderstanding the question

$contacts [] = ['name' => 'Alena Holligan']; $contacts['email'] = 'alena.holligan@teamtreehouse.com'; $contacts [] = ['name' => 'Dave McFarland']; $contacts['email'] = 'dave.mcfarland@teamtreehouse.com'; $contacts [] = ['name' => 'Treasure Porth']; $contacts['email'] = 'treasure.porth@teamtreehouse.com'; $contacts [] = ['name' => 'Andrew Chalkley']; $contacts['email'] = 'andrew.chalkley@teamtreehouse.com';

Hi Travis,

You don't need to specify the array name a second time.

The syntax looks more like this...

<?php

$contact[] = ['key' => 'value', 'key' => 'value'

?>

So each element in the array, and this is a multidimensional array is separated by a comma.

To complete the challenge you need syntax like this.

$contacts [] = ['name'] => 'Alena Holligan', ['email'] => 'alena.holligan@teamtreehouse.com';
travis brown
travis brown
1,292 Points

Thank you for the help

2 Answers

I have the exact code as Raman Matthew, formatted differently, and still nothing. Very annoying.

The Correct answer of task 2 is :May be you should know the correct code:

$contact[] = ['key' => 'value', 'key' => 'value'];

$contacts[] = ['name' => 'Alena Holligan', 'email' => 'alena.holligan@teamtreehouse.com']; $contacts[] = ['name' => 'Dave McFarland', 'email' => 'dave.mcfarland@teamtreehouse.com']; $contacts[] = ['name' => 'Treasure Porth', 'email' => 'treasure.porth@teamtreehouse.com']; $contacts[] = ['name' => 'Andrew Chalkley', 'email' => 'andrew.chalkley@teamtreehouse.com'];

travis brown
travis brown
1,292 Points

Thank you for the help, I understand it now.