Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<html> | ||
|
||
|
||
<?php | ||
error_reporting(E_ALL); | ||
ini_set('display_errors', 1); | ||
|
||
?> | ||
<body> | ||
<p> | ||
<?php | ||
$food = array('pizza', 'salad', 'burger'); | ||
$salad = array('lettuce' => 'with', | ||
'tomato' => 'without', | ||
'onions' => 'with'); | ||
|
||
$pizza = array('cheese' => 'with', | ||
'pepperoni' => 'without', | ||
'mushrooms' => 'with'); | ||
|
||
$burger = array('cheese' => 'without', | ||
'bread' => 'without', | ||
'bacon' => 'with', | ||
'onions' => 'without', | ||
'lettuce' => 'with', | ||
'mayo' => 'with', | ||
'pickles' => 'with'); | ||
|
||
// Looping through an array using "for". | ||
// First, let's get the length of the array! | ||
$length = count($food); | ||
|
||
// Remember, arrays in PHP are zero-based: | ||
for ($i = 0; $i < $length; $i++) { | ||
echo $food[$i] . '<br />'; | ||
} | ||
|
||
echo '<br /><br />I want my salad:<br />'; | ||
|
||
// Loop through an associative array using "foreach": | ||
foreach ($salad as $ingredient=>$include) { | ||
echo $include . ' ' . $ingredient . '<br />'; | ||
} | ||
|
||
|
||
// Create your own array here and loop | ||
// through it using foreach! | ||
echo '<br /><br />I want my pizza:<br />'; | ||
|
||
foreach ($pizza as $ingredient=>$include) { | ||
echo $include . ' ' . $ingredient . '<br />'; | ||
} | ||
|
||
echo '<br /><br />I want my burger:<br />'; | ||
|
||
foreach ($burger as $ingredient=>$include) { | ||
echo $include . ' ' . $ingredient . '<br />'; | ||
} | ||
|
||
?> | ||
</p> | ||
|
||
</body> | ||
</html> |