Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Iteration Nation</title>
- </head>
- <body>
- <p>
- <?php
- $food = array('pizza', 'salad', 'burger');
- $salad = array('lettuce' => 'with',
- 'tomato' => 'without',
- 'onions' => '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 />';
- }
- echo '<br /><br />';
- // Create your own array here and loop
- // through it using foreach!
- $array_kamu = array(1610, 'VOC Belanda', 350);
- foreach ($array_kamu as $ingredient=>$include) {
- echo $include . ' ' . $ingredient . '<br />';
- }
- ?>
- </p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement