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

tristan marroquin
tristan marroquin
2,491 Points

Can you explain to me more on why nothing will be displayed is it because if ($username) at the start is false?

Can you explain to me more on why nothing will be displayed is it because if ($username) at the start is false?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, tristan marroquin ! I feel fairly certain you are referring to the code in this question:

$username = "Treehouse";
if ($username) {
    if ($username != "Treehouse") {
        echo "Hello $username";
    }
} else {
    echo "You must be logged in";
}

In this instance, nothing will be displayed at all. There is an outer if else statement. The $username starts off being defined as the string "Treehouse". The first if says what to do if the $username is a "truthy" value. A non-empty string is considered "truthy" so the if executes its code. The else will never be fired because the if evaluated to true.

Now, this part is a bit trickier. Inside the first if statement is yet another if statement. It says what to do if the username was not equal to "Treehouse". But it says nothing of what to do if it was equal to Treehouse :smiley: And since, it was equal to "Treehouse" nothing else will happen. So nothing will be displayed.

Hope this helps! :sparkles: