PHP if else Statements

Back to ACP page

Table of Contents

PHP 1 if else Statement

<h2>if...else_Statement</h2> <p>The if...else statement executes some code if a condition is true and another code if that condition is false.</p> <?php $t = date("H"); if ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>

Example 1

Result View Example

PHP 2 if elseif else Statement

<h2>if...elseif...else Statement</h2> <p>The if...elseif...else statement executes different codes for more than two conditions. </p> <?php // $t = date("H"); $t = 19; echo "<p>The hour (of the server) is " . $t; echo ", and will give the following message:</p>"; if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>

Example 2

Result View Example

Document

Document in project

You can Download PDF file.

Reference