PHP: While Loops

Example 1

Hi my name is Sir Chris

Hi my name is Sir Chris


Example 2

1: Former NBA Player Rod Strickland
2: Former NBA Player Craig Claxton
3: Former NBA Player Rodney Bufford
4: Former NBA Player Marcus Fizer
5: Former NBA Player Darvin Ham

Example 3

[0], => [1], => [2], => [3], => [4], => [5], => [6], => [7], => [8], => [9]


The code used for index.php is below:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../styles.css">
    <title>PHP: While Loops</title>
</head>
<body>

    <h1 class="lesson-h1">PHP: While Loops</h1>

    <?php
    ///////////////////////////////// Example 1 Starts 
    echo "<h4>Example 1</h4>";

    $i = 0;

    while($i < 2){
    echo "<p>Hi my name is Sir Chris</p>";
    $i++;
    }

    ///////////////////////////////// Example 2 Starts 
    echo "<hr>";
    echo "<h4>Example 2</h4>";

    $players = [
        "Rod Strickland",
        "Craig Claxton",
        "Rodney Bufford",
        "Marcus Fizer",
        "Darvin Ham"
    ];

    $count = 0;

    while($count < count($players)){
        echo "<h5>" . ($count + 1) . ": Former NBA Player <span style='background-color: yellow'>$players[$count]</span></h5>";
        $count++;
    }

    //////////////////////////////// Example 3 Starts 
    echo "<hr>";
    echo "<h4>Example 3</h4>";

    $numbers = [0,1,2,3,4,5,6,7,8,9];
    $num = 0;

    echo "<p>";
    while($num < count($numbers)){
        if($num === (count($numbers) - 1)){
            echo "<span>[$num]</span>";
        } else {
            echo "<span>[$num], => </span>";
        }
        $num++;
    }
    echo "</p>";

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