Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Arrays and Control Structures PHP Conditionals Conditionals

Chris Seals
Chris Seals
4,506 Points

Nesting statement help.

I missed this question:


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