The Dark Knight's Tutorials Part I - Looping Through A PHP Array

Did you find this tutorial useful?

  • Yes

    Votes: 1 20.0%
  • No

    Votes: 3 60.0%
  • I already knew it

    Votes: 1 20.0%

  • Total voters
    5

knightcon

New Member
Messages
69
Reaction score
0
Points
0
Hey there, this is a very simple tutorial mainly for beginner PHP coders. This is the first of what I hope will become a very long series of tutorials.

Difficulty: Easy
Coding Time: 10 Minutes
Extensions: None

Overview
This tutorial loops through an array of hyperlinks and outputs them in an unordered list.

hyperlink.php
PHP:
<?php
$array['Link One Caption'] = "page.html";
$array['Link Two Caption'] = "page2.html";
$array['Link Three Caption'] = "page3.html";

echo("<ul>");
foreach($array as $caption=>$link) {
echo("<li><a href='$link'>$caption</a></li>");
};
echo("</ul>");

This code will produce something like the following...
 
Last edited:
Top