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 Daily Exercise Program Adding Logic to Your Programs

Not sure what's wrong with my code?

<?php $name = 'Umar'; $string_one = "Learning to display \"Hello $name\" to the screen."; $string_one = 'Learning to display "Hello ' . $name . " to the screen."; //echo $string_one;

$isReady = true; //var_dump($isReady); $isReady = false; //var_dump($isReady);

//var_dump(1 + "2");

$a = 10; $b = '10';

//var_dump($a === $b);

//var_dump($string_one == 'Learning to display "Hello Umar" to the screen.'); if ($string_one == 'Learning to display "Hello Umar" to the screen'); { echo 'The values mathch'; } elseif ($string_one == "") { echo '$string_one is empty';

} else { echo 'The values DO NOT match'; }

?>

1 Answer

jamesjones21
jamesjones21
9,260 Points

there were a couple of things the single quotes mixed with double quotes, as you were breaking the string it would then throw an error.

your variable:

$string_one = "Learning to display "Hello $name"\ to the screen.";

updated variable: I would output the variable with concatenation, so you add single quotes around the double quotes:

$string_one = "Learning to display " . '"' . 'Hello' . ' ' . $name . '"' . " to the screen.";

Also it won't match as the string output in in $string_one has a full stop in it where in the conditional it doesn't. The following conditional will be commented out due to it being on the same line as the var_dump():

There is also one more thing to be weary of and that is the conditional ending with a semi colon before the curly bracket which will need to be removed.

//var_dump($string_one == 'Learning to display "Hello Umar" to the screen.'); if ($string_one == 'Learning to display "Hello Umar" to the screen');

Updated code below to help you see the picture:

<?php 

$name = 'Umar'; 


$string_one = "Learning to display " . '"' . 'Hello' . ' ' . $name . '"' . " to the screen.";

//$string_one = 'Learning to display "Hello ' . $name . " to the screen."; //echo $string_one;

$isReady = true; //var_dump($isReady); $isReady = false; //var_dump($isReady);

//var_dump(1 + "2");

$a = 10; $b = '10';

//var_dump($a === $b);

//var_dump($string_one == 'Learning to display "Hello Umar" to the screen.');

if ($string_one == 'Learning to display "Hello Umar" to the screen.') {

    echo 'The values mathch'; 

} elseif ($string_one == "") { echo '$string_one is empty';

} else { echo 'The values DO NOT match'; }