A False If Statement: Display
A False If Statement: Display
Did you get that we were comparing the variable $my_name with "someguy" to see if they were equal? In
PHP you use the double equal sign (==) to compare values. Additionally, notice that because the if statement
turned out to be true, the code segment was executed, printing out "Your name is someguy!". Let's go a bit
more in-depth into this example to iron out the details.
A False If Statement
Let us now see what happens when a PHP if statement is not true, in other words, false. Say that we
changed the above example to:
PHP Code:
$my_name = "anotherguy";
if ( $my_name == "someguy" ) {
echo "Your name is someguy!<br />";
}
echo "Welcome to my homepage!";
Display:
Welcome to my homepage!
Here the variable contained the value "anotherguy", which is not equal to "someguy". The if statement
evaluated to false, so the code segment of the if statement was not executed. When used properly, the if
statement is a powerful tool to have in your programming arsenal!