Advertisement

Google Ad Slot: content-top

PHP If Statement


if statement is a fundamental control structure used to execute a block of code only if a specified condition evaluates to true.


Syntax of the if Statement:


if (condition) {
    // Code to be executed if condition is true
}
Example
<?php
if (19 >= 18) {
echo "You are eligible to vote.";
}
?>
Try it yourself

We can also use variables in the if statement:

Example
<?php
$age = 20;

if ($age >= 18) {
echo "You are eligible to vote.";
}
?>
Try it yourself