If...else Statement


The if....else statement executes some code if a condition is true and another code if that condition is false.

Syntax

if (condition) {
    code to be executed if condition is true;
} else {
    code to be executed if condition is false;
}

The example below will output "You Can Give Vote" if the age is Grater than 18, and "You Can not Give Vote" otherwise:

Example

<?php
$age = 18;

if ($age < "18") {
    echo "You Can Give Vote";
} else {
    echo You Can Not Give Vote";
}
?>

Run Example>>