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 trialblake McMullin
1,337 Pointshelp with associative arrays please!
I seem to be having much trouble with the challenge question "Right now, the <h1> element has the year of the original movie as a static piece of text. Replace that with a PHP command that INSTEAD displays the year of the new movie from the array. (Be sure to leave the parentheses intact.)"
I have reached the correct point of: <h1><?php echo $movie["title"]; ?> (1985)</h1> but cannot get past this for some reason... --> how do you replace the "year" but still keep the original parentheses intact?! does this require a DL?
2 Answers
Leonardo Hernandez
13,798 PointsYou can place PHP code anywhere, even between parentheses . Try opening a new PHP code block between them and echo out a variable.
You can also concatenate a string using a period.
<?php echo "Hello " . $fullname . ". My name is Leonardo" ?>
Curtis Schrum
10,174 PointsYou almost have it remember that you can echo out php anywhere
(<?php echo $movie["year"]; ?>)
blake McMullin
1,337 Pointsthanksssss!!!!
Curtis Schrum
10,174 PointsCurtis Schrum
10,174 PointsLeonardo that was such a better written answer than mine LOL. I forgot to wrap my code in a code element. Phone + Forum = Bad Idea.
Leonardo Hernandez
13,798 PointsLeonardo Hernandez
13,798 PointsI admire the acknowledgement ! I also admire the mobile attempt. Thanks !
Mike Baxter
4,442 PointsMike Baxter
4,442 PointsAlso, you don't need the concatenation to add the variable since you're using double-quotes. (You only need to do that if you're using single-quotes, so that you don't write out the variable name instead of the value.) You could just do this:
<?php echo "Hello $fullname . My name is Leonardo" ?>
It's just the difference between interpreted and literal :)
Mike Baxter
4,442 PointsMike Baxter
4,442 PointsThere shouldn't be a space between the variable name and the period, but I can't go back and edit it.