Ternary Operator

You are old enough to join our club 👍

You have enough Subscribers 😀


The code used for index.php is below:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../styles.css">
    <title>Ternary Operator</title>
</head>
<body>

    <h1 class="lesson-h1">Ternary Operator</h1>

    <?php
    $age = 99;
    $subscribers = 1633;

    // if($age >= 18){
    //     $old_enough = true;
    // } else {
    //     $old_enough = false;
    // }

    //This line runs the same as the above if and else statements
    $old_enough = ($age >= 18) ? true : false;

    if($old_enough === true){
        echo "You are old enough to join our club 👍";
    } else{
        echo "You are not old enough to join our club 👎";
        }

    $enoughSubscribers = ($subscribers >= 1000 ? true : false);

    if($enoughSubscribers === true){
        echo "<p>You have enough Subscribers 😀</p>";
    } else {
        echo "<p>You do not have enough Subscribers 😣</p>";
    }

    include('../show_code.php');
    show_code('index.php');
    ?>

</body>
</html>