Professional Documents
Culture Documents
Has someone ever told you, "if you work hard, then you will succeed"? And what happens if you do not
work hard? Well, you fail! This is an example of an if/else conditional statement.
How does this translate into something useful for PHP developers? Well consider this:
Someone comes to your website and you want to ask this visitor her name if it is her first time coming to
your site. With an if statement this is easy. Simply have a conditional statement to check, "are you visiting for
the first time". If the condition is true, then take them to the "Insert Your Name" page, else let her view the
website as normal because you have already asked her for her name in the past.
If/Else an Example
Using these conditional statements can add a new layers of "cool" to your website. Here's the basic form
of an if/else statement in PHP.
PHP Code:
$number_three = 3;
if ( $number_three == 3 ) {
echo "The if statement evaluated to true";
} else {
echo "The if statement evaluated to false";
}
Display:
The if statement evaluated to true
This is a lot to digest in one sitting, so let us step through the code, line by line.