Hi my name is Sir Chris
Hi my name is Sir Chris
[0], => [1], => [2], => [3], => [4], => [5], => [6], => [7], => [8], => [9]
<!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>