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 trialnathanielcusano
9,808 PointsWhy is this returning bool(true)?
I thought that since the operator is for identical that the .$name would screw it up. It's the exact line in my code.
var_dump($string_one=== 'Learning to display "Hello ' .$name. ' " to the screen' . "\n");
2 Answers
Simon Coates
28,694 Points=== just means that the values are the same and that the type is the same. With something like:
<?php
$string_one = "Learning to display \"Hello Pierre \" to the screen\n";
$name = "Pierre";
var_dump($string_one=== 'Learning to display "Hello ' .$name. ' " to the screen' . "\n");
the values are the same, as the comparison occurs after the string concatenation due to operator precedence. The value used in the comparison is the same value as the first. (i'm a little lost as to where the confusion is. If the above answer doesn't fix your confusion, can you clarify and i'll try again?
nathanielcusano
9,808 Pointsoh so like "name" instead of $name ?
Simon Coates
28,694 Pointsaltering the strings wouldn't produce different results between == and ===. you need to be comparing two different types of value for the distinctions between == and === to matter.
nathanielcusano
9,808 Pointsnathanielcusano
9,808 PointsSo if I use == it's still true. So my question really is what would make === false but leave == true with my code?
Simon Coates
28,694 PointsSimon Coates
28,694 Pointswell, you'd need a type mismatch (eg, 1 === "1" vs 1 == "1") . At you seem to be using values that are innately strings, == vs === is moot. If the types are the same, you need the strings to differ in terms of the contained text.