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 Sorting Arrays

Challenge Task 1 - someone help please

Can someone please post a code for this question and see what is wrong with my code? Thank you

https://w.trhou.se/ovlbafod0i

2 Answers

Daniel Gauthier
Daniel Gauthier
15,000 Points

Hey Antonia,

I've looked over your code and it was a good try, but your solution became a little complicated by the end.

First, this is the code the first part of the challenge is looking for:

<?php
//edit this array
$contacts = array(
  array( 'name' => 'Alena Holligan'),
  array( 'name' => 'Dave McFarland'),
  array( 'name' => 'Treasure Porth'),
  array( 'name' => 'Andrew Chalkley')
  );

echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo "<li>Alena Holligan : alena.holligan@teamtreehouse.com</li>\n";
echo "<li>Dave McFarland : dave.mcfarland@teamtreehouse.com</li>\n";
echo "<li>Treasure Porth : treasure.porth@teamtreehouse.com</li>\n";
echo "<li>Andrew Chalkley : andrew.chalkley@teamtreehouse.com</li>\n";
echo "</ul>\n";

The first thing to note is that the first comment asks you to edit the existing array. The challenge will allow you to pass if you create a second assignment to $contacts beneath the existing one, but it makes the code less clean. Notice how the original array has been edited to contain the new associative arrays.

Secondly, you attempted to use the extract function, but it wasn't requested as part of this code challenge. The main concept to learn from this section of the challenge is simply how to create an array of arrays.

We started with this original array:

<?php

$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');

?>

but notice how the array is changed when we turn the original array's strings into associative arrays:

<?php

$contacts = array(
  array( 'name' => 'Alena Holligan'),
  array( 'name' => 'Dave McFarland'),
  array( 'name' => 'Treasure Porth'),
  array( 'name' => 'Andrew Chalkley')
  );

?>

Now we have an array filled with four associative arrays. Take note of the structure of this code since this is what this step in the challenge is attempting to teach you.

Good luck with the course!

Thank you very much, that was really helpful :)

Hi, I've done precisely that and it still shows me Bummer: Try again!. Can anyone explain me what is wrong with my code? I'm on task 1 Thanks

Here it is :

<?php //edit this array $contacts = array ( array ('name' => 'Alena Holligan'), array ('name' => 'Dave Mcfarland'), array ('name' => 'Treasure Porth'), array ('name' => 'Andrew Chalkley') );

echo "<ul>\n"; //$contacts[0] will return 'Alena Holligan' in our simple array of names. echo "<li>Alena Holligan : alena.holligan@teamtreehouse.com</li>\n"; echo "<li>Dave McFarland : dave.mcfarland@teamtreehouse.com</li>\n"; echo "<li>Treasure Porth : treasure.porth@teamtreehouse.com</li>\n"; echo "<li>Andrew Chalkley : andrew.chalkley@teamtreehouse.com</li>\n"; echo "</ul>\n";