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

how do I echo 'Hi,I am Mike' in this code

<?php
$name = "Mike";
if (string==Mike){

}
?>

Tyrone,

Try writing it out in plain English first, instead of code:

name equals Mike

if name equals Mike
    echo Mike

Then try coding that. This helps me often, and I think it's a valuable skill to have, especially when the problem is much larger.

2 Answers

Hi Tyrone!

To use echo, you just do the following:

<?php
echo("Hi, I am Mike");
?>

or you can have it output the name stored in your name variable like this:

<?php
echo("Hi, I am ".$name);
?>

However, in your code I noticed a different issue that might cause you problems. You have:

<?php
if (string==Mike) {
}
?>

I think what you want here is:

<?php
if ($name == "Mike") {
}
?>

Variable names in PHP start with a $ and strings need to be enclosed in either single or double quotes (' and ") or else the interpreter doesn't evaluate them as strings :)

Tim Knight
Tim Knight
28,888 Points

Note that I changed your condition to make it true.

<?php
$name = "Mike";
if ($name=="Mike"){
  echo "Hi, I am " . $name;
}
?>