Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Aimee Ault
Aimee Ault
29,193 Points

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;
}
?>