How to make multiple conditions in php?

by edmond_brakus , in category: PHP General , 10 months ago

How to make multiple conditions in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by addison , 10 months ago

@edmond_brakus 

In PHP, you can make multiple conditions using conditional statements like if, else if, and else, as well as logical operators like && (AND operator) and || (OR operator). Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$age = 30;
$gender = 'female';

if ($age > 18 && $gender == 'male') {
    echo "You are a male adult.";
} else if ($age > 18 && $gender == 'female') {
    echo "You are a female adult.";
} else if ($age <= 18 && $gender == 'male') {
    echo "You are a male minor.";
} else {
    echo "You are a female minor.";
}


In this example, the code checks the age and gender variables to determine the appropriate message to display. The && operator is used to perform an AND operation, which means that both conditions must evaluate to true for the corresponding message to be displayed.