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

Its not for a lack of trying

Currently on part 3 of index.php code test... Looks as follows.. Cant get any output.

<?php //edit this array $contacts = array(array('name'=>'Alena Holligan', 'email'=> 'alena.holligan@teamtreehouse.com'), array('name'=>'Dave McFarland','email'=>'dave.mcfarland@teamtreehouse.com'),array('name'=> 'Treasure Porth','email'=>'treasure.porth@teamtreehouse.com'),array('name'=> 'Andrew Chalkley','email'=> 'andrew.chalkley@teamtreehouse.com'));

//$contacts[0] will return 'Alena Holligan' in our simple array of names. //echo "$contacts[0]['name']"; echo "<ul>\n"; echo "<li>$contacts[0]['name']</li>\n"; echo "<li>$contacts[0]['email']</li>\n"; echo "<li>$contacts[1]['name']:$contacts[1]['email']</li>\n"; echo "<li>$contacts[2]['name']:$contacts[2]['email']</li>\n"; echo "<li>$contacts[3]['name']:$contacts[3]['email']</li>\n"; echo "</ul>\n";

Like i said, not for lack of trying....

just to make life easier

<?php 
//edit this array 
$contacts = array( 
     array ( 'name'=>'Alena Holligan', 'email'=> 'alena.holligan@teamtreehouse.com'), 
     array( 'name' => 'Dave McFarland', 'email' => 'dave.mcfarland@teamtreehouse.com' ), 
     array( 'name'=> 'Treasure Porth','email'=>'treasure.porth@teamtreehouse.com' ),
     array('name'=> 'Andrew Chalkley','email'=> 'andrew.chalkley@teamtreehouse.com')
);

//$contacts[0] will return 'Alena Holligan' in our simple array of names. 
//echo "$contacts[0]['name']"; 
echo "<ul>\n"; 
     echo "<li>$contacts[0]['name']</li>\n"; 
     echo "<li>$contacts[0]['email']</li>\n"; 
     echo "<li>$contacts[1]['name']:$contacts[1]['email']</li>\n"; 
     echo "<li>$contacts[2]['name']:$contacts[2]['email']</li>\n"; 
     echo "<li>$contacts[3]['name']:$contacts[3]['email']</li>\n"; 
echo "</ul>\n";

7 Answers

OMFG Jason 3 days of pain on the train to and from work over spaces on either side of a colon... Arrrghh..... Thanks i got through... I think it could be helpful if they afd a function to their checking that returns the line error or expected character missing to their response dor incorrect submission

Don't be too hard on yourself. It's a common error to make on code challenges.

yes, I have just came to this exercise also and examined the problem, and I got some results... If you want to output an array inside double quotes, it needs to be placed inside curly braces {}, reference here (example 4): http://php.net/manual/en/function.array.php#example-5596

The other option is to concatenate string, like:

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

Hi Stu,

I'm not sure if you passed the challenge or not yet but the curly braces mentioned by Daniel and also the string concatenation example will both pass the challenge.

You want to make sure that the output is exactly the same as it was before. For example, it's important to have a single space before and after the colon since that's what the original output had.

Post what you currently have for the echo section if you're still having trouble.

Problem being is none of that gives me any output

Wondering what is wrond with my syntax

Both give correct output, but neither what they wanted l.. They both worked tho thanks

Creation of output not specified, but its telling me off for modifying output hahah

I ran over concatenation script.. Did try earlier.. This time got correct output, but not how they want it

then use curly braces... Was the way how you create output specified?