Conditions if..else in PHP. Code example open

Conditions if..else in PHP. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators

Conditional constructions allow to direct work of the program depending on a condition on one of possible ways.

if(condition) {
   // what needs to happen
}

if example:

$age = 17;

if($age == 18) {
    echo 'You are an adult';
}

Several conditions:

if($age == 18 && age <= 30) {
    echo 'You are young!!!';
}

If the condition is not met then execute the code in else

if($age == 18 && age <= 30) { echo 'You are young'; } else { echo 'You are elderly'; } If you want to set an additional condition for else:

if($age == 18 && age <= 30) {
    echo 'You are young';
} elseif ($age > 65) {
    echo 'You are retired';
}
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation