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 Conditionals & Loops Conditionals Challenge

Ross Finn
Ross Finn
5,292 Points

php basics, conditionals and loops, can;t figure this out, watched the video a dozen times.

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

I can't figure this one out. This what I've come up with. Anyone any ideas?

3 Answers

Ethan Lowry
PLUS
Ethan Lowry
Courses Plus Student 7,323 Points

You shouldn't have the equals sign after echo - you're not assigning anything to echo, you're calling the echo function and passing it a string. Thus that section of the code should just be:

if($name == 'Mike'){ echo "Hi, I am Mike!"; }

But that's not all - remember we use variables for a reason: to allow for easy reuse of code. Look for somewhere in your code that you're writing something twice when you could be using your variable/s instead. :)

If you want, you can find some further explanation of echo here.

Michael Hulet
Michael Hulet
47,913 Points

I notice one problem with your code right off the bat. You have an = between echo and "Hi, I am Mike!" in your if statement, as if echo is a variable. With commands in PHP, you shouldn't put an = between the command and any of its parameters. Also, you assigned $info to that string value for a reason. See if this works:

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

Also, I prettified your code to make it easier to read. To learn how to do this yourself, check out the Markdown Cheatsheet, under the box where you'd type a reply

Ross Finn
Ross Finn
5,292 Points

Agh! What was I thinking. Silly mistake. Thanks guys.