0% found this document useful (0 votes)
36 views

A False If Statement: Display

The document explains PHP if statements by providing an example that compares a variable $my_name to a string "someguy" using ==. When $my_name equals "someguy", the if statement evaluates to true and the code inside the if statement is executed, printing "Your name is someguy!". It then modifies the example to set $my_name to "anotherguy", causing the if statement to evaluate to false and skipping the code inside the if statement.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

A False If Statement: Display

The document explains PHP if statements by providing an example that compares a variable $my_name to a string "someguy" using ==. When $my_name equals "someguy", the if statement evaluates to true and the code inside the if statement is executed, printing "Your name is someguy!". It then modifies the example to set $my_name to "anotherguy", causing the if statement to evaluate to false and skipping the code inside the if statement.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Display:

Your name is someguy!


Welcome to my homepage!

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.

• We first set the variable $my_name equal to "someguy".


• We next used a PHP if statement to check if the value contained in the variable $my_name was equal
to "someguy"
• The comparison between $my_name and "someguy" was done with a double equal sign "==", not a
single equals"="! A single equals is for assigning a value to a variable, while a double equals is for
checking if things are equal.
• Translated into english the PHP statement ( $my_name == "someguy" ) is ( $my_name is equal to
"someguy" ).
• $my_name is indeed equal to "someguy" so the echo statement is executed.

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!

You might also like