Account
Categories

If-else Statement


To check the condition in PHP, if the criteria are met (true), the code inside the if braces will execute.

If the condition is not true (false), then the code inside the else braces will execute.

Syntax:
if (condition) {
    //  If the condition is true then code executes.
} else {
    //If the condition is false then code executes.
}
Example:
<?php
$number = 8;

if ($number > 10) {
    echo "Number is greater than 10";
} else {
    echo "Number is 10 or less";
}
?>
Output:
Number is 10 or less.