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

Maxwell Kendall
seal-mask
.a{fill-rule:evenodd;}techdegree
Maxwell Kendall
Front End Web Development Techdegree Student 12,102 Points

Conditonals Challenge task 2 of 3

I cant figure out how to test to see if the variable name is equal to the string mike

This is what I have tried to do:

<?php

$name = "Mike" if($name = "Mike"){}

?>

I know this is pretty stupid I just cant figure it out, thanks!

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

}
  ;
?>

2 Answers

Julian Aramburu
Julian Aramburu
11,368 Points

Hi mate! You almost got it right! When you are trying to compare something to something you should use == double equal signs for "equal" and === triple equal signs for "strict equal" otherwise if you use just one set of equal sign you are "re-declaring" the variable... so the if statement should be:

<?php
if($name === "Mike") {
  //something happens in here if the condition is met
}         

Also you have an extra semi colon after "Mike" so fix that too :)!

Hopes you find this useful!

Cheers and keep coding!

Edited by adding <?php for formatting.

You also need a semicolon after your variable assignment:

<?php
$name = "Mike";