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 Arrays and Control Structures PHP Conditionals Conditionals

Chris Seals
Chris Seals
4,507 Points

Nesting 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)"

Gabe Hoverman
Gabe Hoverman
512 Points

The 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".

1 Answer

$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.