July 15, 2017

Core PHP: The Elseif Statement (5.3)

The Elseif Statement

For example:
<?php
$age = 21;

if ($age<=13) {
   echo "Child.";
} elseif ($age>13 && $age<19) {
   echo "Teenager";
} else {
   echo "Adult";
}

//Outputs "Adult"
?>

We used the logical AND (&&) operator to combine the two conditions and check to determine whether $age is between 13 and 19.

No comments:

Post a Comment