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 trialAndrey Volsky
1,290 PointsWhy does my result ends up with bool(false) every time?
I've been trying to figure out why during the last part of the video when I tried to follow along with my own script it always gave me a false result.
I've checked the code and it seems similar to one provided in the video, with my own name instead...
<?php $name = 'Andrey';
$string_one = "Learning to display \"Hello $name!\" to the screen. \n"; $string_one = 'Learning to display ';
$string_one .= '"Hello ';
$string_one .= $name;
$string_one .= '!" to the screen. ';
//$string_one .= $string_one . "\n";
//$string_one = 'I am ' . $string_one;
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($a === $b);
var_dump($string_one == 'Learning to display "Hello Andrey !" to the screen.');
?>
But it always ends up false. Please help, what have I done wrong?
2 Answers
Steven Parker
231,268 PointsThe strings are actually different, so they don't match. When building string_one:
$string_one .= '!" to the screen. ';
// ^ there is a space here at the end
But when comparing it:
var_dump($string_one == 'Learning to display "Hello Andrey !" to the screen.');
// ^ there is an extra space here
// ^ but not here
In the video, neither of those spaces are used.
Christopher Beckett
1,289 PointsI'm having the same problem as the person above. I checked all extra space and all letters, making sure they were capitals where they were are meant to be and checked against early videos making sure the text is the same but mines still comes back false also.
<?php $name ='chris'; $string_one = "Learning to display \"Hello $name!\" to the screen.\n"; $string_one = 'Learning to display'; $string_one .= '"Hello '; $string_one .= $name; $string_one .= '!" to the screen.'; //$string_one = $string_one . "\n"; //$string_one = 'I am ' . $string_one; 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($a === $b);
var_dump($string_one == 'Learning to display "Hello Chris!" to the screen.');
?>
Steven Parker
231,268 PointsAlways create a new question instead of posting one as an "answer" to another question. You might want to take a look at this video about Posting a Question.
And when possible, always share code using a snapshot of your workspace; otherwise use Markdown formatting to preserve the code's appearance.
Andrey Volsky
1,290 PointsAndrey Volsky
1,290 PointsI'll try it! Thanks for your answer.