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 trialTyrone Taylor
Courses Plus Student 11,792 Pointsphp
how do I echo 'Hi,I am Mike' in this code
<?php
$name = "Mike";
if (string==Mike){
}
?>
2 Answers
Aimee Ault
29,193 PointsHi 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
28,888 PointsNote that I changed your condition to make it true.
<?php
$name = "Mike";
if ($name=="Mike"){
echo "Hi, I am " . $name;
}
?>
James Gill
Courses Plus Student 34,936 PointsJames Gill
Courses Plus Student 34,936 PointsTyrone,
Try writing it out in plain English first, instead of code:
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.