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 Creating the Menu and Footer Variables

Coding isn't really my thing help please

Task:

Here's a block of PHP code that displays the name of our website on the screen. Let's modify this to use a variable instead. Right now, the code displays the name of our website on the screen. Modify it to assign the name of our website to a variable called "name". (Don't forget to use a dollar sign in the variable name.)

Existing Code:

<?php

echo "Shirts 4 Mike";

?>

what do I add to it?

2 Answers

Richard Duncan
Richard Duncan
5,568 Points

$name = "Shirts 4 Mike";

echo $name;

Thank you for that! It did the job.

Richard Duncan
Richard Duncan
5,568 Points

No worries, sometimes when you have been over and over something it's good to start with the solution and work backwards. It's bound to be a bit alien if you're looking at it for the first time, hang in there!

James Barnett
James Barnett
39,199 Points

Richard Duncan -

Now that you've given the answer. How does that help someone new to programming understand the concept of variables or learn how to debug their first program?

This is an honest question, I'm curious on thought process as it's different then my inital inclination when seeing questions like this.

Richard Duncan
Richard Duncan
5,568 Points

James Barnett in my experience in the real world there isn't always someone to ask. You see a feature and read it but there are many ways to achieve things. I'm mostly self taught and have done this by starting with the solution and researching what I didn't understand. If this had been a complex problem I'd have left a write up but as (in my opinion) he needed a nudge I didn't think it was necessary. Sorry to whoever felt the need to down vote, twice but I answered the question.

Stone Preston
Stone Preston
42,016 Points

creating a variable in PHP and echoing it out on screen would look something like this

<?php

$variableName = someValue;

echo $variableName;

?>

If you are struggling with any challenge, I would recommend you go back and watch the video again until you understand. It isnt a good idea to move forward without understanding things, especially something like variables which are a foundation of programming

Thank you, and yes i plan on reviewing the section many more times till I get done by myself for sure.