Let's Get Started with a PHP for
Loop Page!
- Open Notepad++
- Choose:
File -> New
- Copy the PHP
for
Template (PHP) code (below)
- Paste that code into your new file
- Change the put-title-of-this-page-here,
put-welcome-heading-here, and put-welcome-paragraph here
strings.
- Click: File -> Save As
- Name your file: \www\for.php
- Change the
Save as type:
to: PHP Hypertext Preprocessor (*.php)
- Click: Save
- Visit your page (http://buffalo.edu/for.php) in your favorite web browser
- Make any changes
- Save your changes
- Change the array items to something else (fruits, hobbies, songs, etc)
- Save your changes
- Reload your web page
PHP for
Template (PHP)
<?php
$title = "put-title-of-this-page-here";
$h2 = "put-heading-of-this-page-here";
$par = "put-paragraph-of-this-page-here";
$myArray = array("item-0", "item-1", "item-2", "item-3", "item-4");
?>
<!doctype html>
<html>
<head>
<title><?php echo($title); ?></title>
<head>
<body>
<h2><?php echo($h2); ?></h2>
<p><?php echo($par); ?></p>
<?php
for ($i = 0; $i < count($myArray); $i++) {
echo("Item " . $i . " is " . $myArray[$i] . "<br/>\n");
}
?>
</body>
</html>
Output