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 PHP Basics (Retired) PHP Data & Structure PHP Variables

very frustrated, not sure what I'm doing wrong? <?php $name ="Mike"?> <?php echo = "Mike"?>

PHP basics part 2, is asking to echo mikes name to the screen?

index.php
<?php $name ="Mike"?> 

<?php echo = "Mike"?>

<?php $name = "Mike"; echo $name; ?>

out of all the answers that is the only one that worked. not sure if its an issues with workspaces or im still a noob? :) thanks everyone!

4 Answers

Patrizia Lutz
Patrizia Lutz
1,449 Points

You can't assign a value to echo, which is a PHP function that outputs a string (or multiple strings).

http://php.net/echo

You should declare the variable $name and assign the value "Mike". Then use echo to print it out.

<?php $name = "Mike"; ?>
<?php echo $name; ?>

or

<?php 
$name = "Mike";
echo $name;
?>

You can also concatenate strings and variables like so:

<?php echo 'Hi, my name is ' . $name . '.'; ?>
//=> Hi, my name is Mike.

I moved your answer to answer so it could be selected as "best answer" I realized I was missing a semi-colon in my answer.

Jeff Lemay
Jeff Lemay
14,268 Points

KEEP EVERYTHING IN A SINGLE PHP BLOCK! This question comes up often. There should really be an instruction added to the code challenge.

But you also have some other issues...

  • When you combine the two statements into a single php block, you'll need to close each with a semi-colon (well, technically, you only need to close the first one where you set the name variable)
  • You are not echoing the variable properly. You tried echoing just a string, but you don't use an equal sign for echoing variables/strings.
<?php
$name = "Mike"; 
echo $Mike;
?>

thank you for responding! this objective is driving me crazy haha, i get what your saying but unfortunately this didnt work in workspaces.

Jeff Lemay
Jeff Lemay
14,268 Points

Oops, it should be echo $name

You almost had it. You created the variable some instead of typing "mike" every time you're able to just call on the variable.

<?php $name ="Mike";

echo $name; ?>

ahhh thank you so much!!

If you look at all the answers they're basically the same thing. I think it may be how you entered your answer.