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 trialChris Seals
4,507 PointsNesting statement help.
I missed this question:
<?php
$username = "Treehouse"; if ($username) { if ($username != "Treehouse") { echo "Hello $username"; } } else { echo "You must be logged in"; } ?>
I believe the reason why is that I dont fully understand what evaluation is taking place for "if ($username)"
1 Answer
molo
8,927 Points$username = "Treehouse"; - Assigning the value Treehouse to $username
if($username); - This check is the username exists and a value is assigned. As $username exists from the code above and the value 'Treehouse' is assigned to it, it will run the statement inside the if block.
Gabe Hoverman
512 PointsGabe Hoverman
512 PointsThe statement "if ($username)" is checking to see if the variable $username exists, and if it is assigned to a value (e.g. it is not equal to null). If this is the case, then it will move on to the next statement.
The example in the quiz will not echo anything out onto the screen, as the username does exist, but it IS equal to "Treehouse".