Skip to content

Instantly share code, notes, and snippets.

@Dyrits
Forked from codecademydev/index.php
Last active February 19, 2024 00:10
Show Gist options
  • Save Dyrits/cd27ab2fa78f4c448458e34be7b1af15 to your computer and use it in GitHub Desktop.
Save Dyrits/cd27ab2fa78f4c448458e34be7b1af15 to your computer and use it in GitHub Desktop.
Repetitive Cafe

Repetitive Cafe

Make use of some of the PHP loop shorthand to create HTML for a restaurant menu. Practice using the different loop types with HTML.

<?php
$drinks = [
"Latte" => 3.99,
"Coffee" => 2.00,
"Tea" => 2.50,
"Mocha" => 4.50
];
$pastries = [
"Croissant",
"Muffin",
"Slice of Pie",
"Slice of Cheesecake",
"Cupcake",
"Brownie"
];
?>
<h1>Welcome to the Repetitive Cafe</h1>
<h3>Drinks!</h3>
<ul>
<?php foreach($drinks as $drink=>$price):?>
<li><?="$drink: $$price"?></li>
<?php endforeach;?>
</ul>
<h3>Pastries! ($2 each)</h3>
<ul>
<?php foreach($pastries as $pastrie):?>
<li><?="$pastrie"?></li>
<?php endforeach;?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment