Let's Get Started with a PHP Arrays Page!

  1. Open Notepad++
  2. Choose: File -> New
  3. Copy the PHP Arrays Template (PHP) code (below)
  4. Paste that code into your new file
  5. Change the put-title-of-this-page-here, put-welcome-heading-here, and put-welcome-paragraph here strings.
  6. Put some items in the five (5) array elements here:
  7. Click: File -> Save As
  8. Name your file: \www\arrays.php
  9. Change the Save as type: to: PHP Hypertext Preprocessor (*.php)
  10. Click: Save
  11. Start your local web server if it is not already running
  12. Visit your page (http://localhost/arrays.php) in your favorite web browser
  13. Make any changes
  14. Save your changes
  15. Change the array items to something else (fruits, hobbies, songs, etc)
  16. Save your changes
  17. Reload your web page

PHP Arrays 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
    echo("Item 0 is " . $myArray[0] . "<br/>\n");
    echo("Item 1 is " . $myArray[1] . "<br/>\n");
    echo("Item 2 is " . $myArray[2] . "<br/>\n");
    echo("Item 3 is " . $myArray[3] . "<br/>\n");
    echo("Item 4 is " . $myArray[4] . "<br/>\n");
    ?>   
  </body>
</html>
Output