<!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: Foreach Loops</title>
</head>
<body>
<h1 class="lesson-h1">PHP: Foreach Loops</h1>
<?php
// Example 1 Code /////////////////////////////////////
echo "<h2>Example 1</h2>";
$numbers = [1, 2, 3, 4];
foreach( $numbers as $number ){
echo "<h5>I have $number pieces of chocolate</h5>";
}
// Example 2 Code /////////////////////////////////////
echo "<h2>Example 2</h2>";
$games = ["Poker", "Uno", "Rummy", "Dominos"];
foreach ($games as $game) {
echo "<button>$game</button> ";
}
// Example 3 Code /////////////////////////////////////
echo "<h2>Example 3</h2>";
$stuff = ["Boobers", true, 99, "Rawr"];
foreach ($stuff as $thing) {
echo "<h4>". $thing ."</h4>";
}
include('../show_code.php');
show_code('index.php');
?>
</body>
</html>