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 Build a Simple PHP Application Listing Inventory Items Associative Arrays

help 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

You 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" ?>

Leonardo that was such a better written answer than mine LOL. I forgot to wrap my code in a code element. Phone + Forum = Bad Idea.

I admire the acknowledgement ! I also admire the mobile attempt. Thanks !

Mike Baxter
Mike Baxter
4,442 Points

Also, 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
Mike Baxter
4,442 Points

There shouldn't be a space between the variable name and the period, but I can't go back and edit it.

You almost have it remember that you can echo out php anywhere

(<?php echo $movie["year"]; ?>)

thanksssss!!!!