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 trialZander Curtis
10,634 PointsWhat's Wrong With This Code?
Treehouse Community rocks! Can you help me on this one. I think I'm close :-)
<?php
/*
{
"name": "Username",
"profile_name": "profile_username",
"profile_url": "http://myapi.net/profile_username"
"courses": [
{ "name": "WordPress Plugin Development" },
{ "name": "WordPress Theme Development" },
{ "name": "Introduction to PHP" }
]
}
*/
?>
<ul>
<?php for( $i = 0; $i < count($my_plugin_profile->courses); $i++ ): ?> {
<?php echo $plugin_profile->{'courses'}[$i]->{'names'}; ?>
}
<?php endfor; ?>
</ul>
2 Answers
mikes02
Courses Plus Student 16,968 PointsThere's a few issues with your code.
- There's no need to have the curly braces where you have them. In that setup they would just be displayed as is and would not be doing anything.
- You are using $plugin_profile as your variable when it is actually $my_plugin_profile, so you are referencing the wrong variable.
- The challenge wants you to output each course name within a list item element, you can do this by echoing out the opening and closing li tags and concatenate them with the rest of your code.
- You are referencing the course names as "names" instead of "name"
<?php echo '<li>'.$my_plugin_profile->{"courses"}[$i]->{"name"}.'</li>'; ?>
Zander Curtis
10,634 Pointsmike02,
Thank you so much for taking the time to help me through this exercise. It means a lot :-)
ZanderCurtis
Henrik Hansen
23,176 PointsHenrik Hansen
23,176 PointsThanks! I tried:
Witch did not work in the challenge, but works in "real" code.
velochicdunord
4,816 Pointsvelochicdunord
4,816 PointsThat worked.