1: Hi my name is Sir Chris
2: Hi my name is Sir Chris
3: Hi my name is Sir Chris
4: Hi my name is Sir Chris
<!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: For Loops</title>
</head>
<body>
<h1 class="lesson-h1">PHP: For Loops</h1>
<?php
// Example 1 Code /////////////////////////////////////////////
$num = 0;
echo "<h4>Example 1</h4>";
for($i = 0; $i < 4; $i++){
echo "<p>".($num + 1).": Hi my name is Sir Chris</p>";
$num++;
}
// Example 2 Code /////////////////////////////////////////////
echo "<hr><h4>Example 2</h4>";
$cookies = [
"Chocolate Chip",
"Oatmeal Raison",
"Snickerdoodle",
"Grasshopper"
];
echo "<ol>";
for ($i = 0; $i < count($cookies); $i++) {
echo "<li>$cookies[$i] Cookies.</li>";
}
echo "</ol>";
// Example 3 Code /////////////////////////////////////////////
echo "<hr><h4>Example 3</h4>";
$clients = [
["name" => "Chris Tow", "age" => 38, "is_cool" => true],
["name" => "Rick Jebley", "age" => 65, "is_cool" => false],
["name" => "Ronald O'Neal", "age" => 33, "is_cool" => false],
["name" => "Inga Marie", "age" => 40, "is_cool" => true],
];
for ($i = 0; $i < count($clients); $i++) {
if($clients[$i]["is_cool"] === false){
echo "<h3>" . $clients[$i]['name'] . " is a " . $clients[$i]['age'] . " year old piece of shit.</h3>";
} else {
echo "<h3>" . $clients[$i]['name'] . " is a " . $clients[$i]['age'] . " year old gem of a client.</h3>";
}
}
include('../show_code.php');
show_code('index.php');
?>
</body>
</html>