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'; }
Conditions switch case in PHP. Code example
May 4, 2022