In either web or desktop programming, most of the time, your codes need to produce different results or output depending on one or more conditions. For example, if you want to your webpage to write “Good Morning”, “Good Afternoon” or “Good Evening”, you will need to test first if the current time is considered as morning, afternoon or evening. Another example is when someone entered his username and password to your website’s login page and clicks submit. On your script, you will need to check if the username is existing at the database and the password for that username is correct. If authenticated, you would give him access to your website, otherwise, he would be redirected back to the login page with the message “Incorrect Login!”.

In PHP programming, the if statement is all you need for this kind of situation. The basic syntax for IF statement is:

if ($godisgood)
    praiseHim();

This IF statement checks if the boolean statement, that is $godisgood variable inside parenthesis, when converted to boolean data type, would evaluate as true. Boolean statement can also be two variables or more variable or constants, compared using the boolean operators such as ==, >, <, !=, and so on. So we can also put something like $god > $satan, $jesusislord == true or $jesuslovesyou != false.  If the boolean statement evaluates as true, the line preceeding the if statement, that is praiseHim() function, will execute. You can also execute group of codes by enclosing that inside open and close parenthesis, like the following:

if ($godisgood) {
    praiseHim();
    $soulwinning++;
}

If you want to execute a code or group of codes, when the boolean statement evaluates as false, use the else keyword.

if ($godisgood) {
    praiseHim();
    $soulwinning++;
} else {
    $lifeismiserable = true;
}

Sample codes using if statement

// since adam fell
$man_condemned_to_hell = true;
$guilt = 1;

// man cannot reach God
if ($commit_adultery == true) {
    $man_condemned_to_hell = true;
    $guilt++;
} elseif ($commit_theft == true) {
    $man_condemned_to_hell = true;
    $guilt++;
} elseif ($faithful_to_devotion == false) {
    $man_condemned_to_hell = true;
    $guilt++;
} elseif ($wordliness > $spirituality) {
    $man_condemned_to_hell = true;
    $guilt++;
} elseif ($way_of_living != $biblical) {
    $man_condemned_to_hell = true;
    $guilt++;
}

// but jesus reached out for us
if ($man_accepted_jesus) {
    $man_condemned_to_hell = false;
    $guilt = 0;
    $blessings++;
    winSoulsForJesus();
}

a weather report from five hundred thousand years ago? | unfinished something, almost | Trebizond | Star Nest | The Claim