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 trialRossella Rosin
15,734 PointsWhy "Bummer!"?
I honestly don't understand what I'm supposed to do here. I'm always getting Bummer! for different reasons, even if the code works and does the job. I'm required to replace the hard coded names and email addresses with the corresponding elements from the mutidimensional array. I do it and most of the times its says I should not be modifiying the output at this point. But the output is just as expected if I do what I'm required, and the preview shows the correct list of names and addresses. Then every once in a while it says "ooops! it looks like Task 1 is no longer passing". I've already started all over twice, and since restarting to write nested associative arrays is pretty boring, I'm asking for help. Can someone explain to me with different words, what this exercise is expecting me to do, please? Today's just not my day, obviously.
<?php
//edit this array
$contacts = array(
['name'=>'Alena Holligan', 'email' => 'alena.holligan@teamtreehouse.com'],
['name' =>'Dave McFarland', 'email' => 'dave.mcfarland@teamtreehouse.com'],
['name'=>'Treasure Porth', 'email' => 'treasure.porth@teamtreehouse.com'],
['name'=>'Andrew Chalkley', 'email' => 'andrew.chalkley@teamtreehouse.com'],
);
echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo "<li>" . $contacts[0]['name'] . ": " . $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";
To explain why the code is like this:
In the first step that's what was required: In the code below, we have a simple array of contact names. We want to use the $contacts array to fill in the hardcoded list of names and email addresses. To hold the email as well as the name for each contact, we need a multidimensional array, meaning each person in the contact list will have their own array. The first step is to make each person their own single item ASSOCIATIVE array, using 'name' as the key for these internal arrays.
the second requires to do the same, with email, using 'email' as the key for the internal arrays
Until here, all is fine and $contacts, as created above, passes the test.
The problem is with step 3:
** Replace the hard coded values in the output with the name and email values from the contacts array**
2 Answers
Rossella Rosin
15,734 PointsI just discovered that my problem was that I should have used " : " ( notice the space before the : ) instead of ": " in my output :-/
nico dev
20,364 PointsHaha don't worry, Rossella Rosin, we all have those days |o| , but then we laugh on them once we climb the wall.
I am not sure there, but did you try making the name the key, and the email its value? I think that'd do.
If you are uncertain of what I mean, just let me know and I'll be glad to give you an example.
Rossella Rosin
15,734 PointsI will try that, thank you - btw it's also what I would have chosen had I to do something like that :-). It just didn't seem from the description that I had to do it that way but perhaps I just needed more coffee ;-)
Teacher Russell
16,873 PointsTeacher Russell
16,873 PointsI was stuck on this same challenge, and found your question. I don't understand why you said that you should have used ":" instead of ":" in your output, and also about using the name as the key and email as the value? :) I'm more confused now after reading what helped you, so remember, there's someone out there having a worse day and even more in need of coffee than you:) I know that if I don't take regular breaks, and code too late, the simplest things..........
Rossella Rosin
15,734 PointsRossella Rosin
15,734 PointsThe fact that you missed it, Russell consoles me. It means I'm not the only one who overlooks such subtle details while in coffeine withdrawal :-) The correct " : " has a SPACE before and after the :, not just after and the code was incorrect just because of that. I went nuts for hours because of a missing space in the string. Hope this fixes your code too, so I can think those hours at least helped someone !
Teacher Russell
16,873 PointsTeacher Russell
16,873 PointsIt definitely helped me on my way. I ended up doing the arrays a little differently, giving each person their own array with the variable at the beginning (unnecessary I guess, but easy to read), then echoing the same way, using the curlys. It didn't work at first, and then I played with spaces and eventually it worked. I made good notes and just practice typing these things over and over. Too many hours of this and your mind and eyes can play tricks on you. Stay relaxed and know when to walk away:) Thanks for your help.