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.

Now you will clearly understand the code logic with the help of the flowchart.

If-else Flowchart :


First step: → You will write the program
                    |
Second step: → Now you will check the condition (yes/no)

If you find "Yes", then
                    |
              Execute Code

If you find "No", then
                    |
              Skip the Code

                    |
              End the program

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.