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

Wow i realy need the translation to this code

i was trying to interpret to it like this : $username = "Treehouse";(it means $username=treehouse) if ($username) { (why does this line here ?to confuse?) if ($username != "Treehouse") { my interpret= (if $username is not treehouse ) echo "Hello $username"; my interpret=( hello treehouse ) } } else { echo "You must be logged in"; my interpret (just "you must log in" without username) } if some one can interpret it for me it will help me a lot . regards omer

1 Answer

$username = "Treehouse"; 
if ($username) {  //if the $username holds any value; besides values that are considered equal to false (0, false, undefined) then continue to next if statement
    if ($username != "Treehouse") { //if the value stored in $username is anything besides "Treehouse" then echo
        echo "Hello $username";
    }
} else { //if $username returns false then
    echo "You must be logged in";
}

In this particular challenge, there is no condition for when $username equals "Treehouse". The first condition checks to see if $username exists (if it returns true). If it does, then it checks to see if the $username is anything besides "Treehouse". If there was an else there, that would execute some code if $username was "Treehouse". The final else is to be ran if the first if condition is false; meaning $username doesn't hold anything

thanks ricardo .god bless you ! without conditions :)