if the conditions are positive, we can run another block of code even if the conditions are not met by using else while running the codes in the parentheses {…}.

Let’s show by applying on our example:

<?php
$a = 200;
if($a > 0 && $a < 100) {
   echo '$a variable is between 0-100';
} else {
   echo '$a variable is NOT between 0-100';
}
?>

Here, if the conditions are not correct, we said write $a variable NOT between 0-100. And this time, because we give the value 200 to $a, it will write $a variable is NOT 0-100 on the screen.

Let’s show another example of both the if and else event. You must be over 18 to get a driver’s license. Let’s express this situation using if and else:

<?php
$year = 2020;
$birth_year = 1999;
$age = $year - $birth_year;
if ($age >= 18) {
	    echo 'You can get a driver license!';
} else {
	$remaining_year = 18 - $age;
	echo 'To get the driver license you have to wait ' . $remaining_year . ' more years.';
}
?>

We have done a driver’s license test with both age calculation and if above. If our age is older than or equal to 18, you can get a Driving License on the screen. If it is not less than or equal to 18, he will subtract 18 from age and find the year remaining to be 18 and write how many years we will need to get a driver’s license on the screen.