This post will show you how to build a string of links from an array using PHP.
In our Internoetics downtime, we would have put together about 70 or so of our own (mostly crappy) websites. For virtually all of the sites that we built, we had a simple configuration file that contained global variables meaning that we could quickly and easily effect site changes. That included using user-defined arrays to generate header and footer menus.
The Output
Here's a snapshot from one of the site that utilises similar code. The footer menu is in the bottom right of the image. Simple, right?
The Code
Usage
Use the function as follows:
The HTML that's generated would output as follows:
We use a pipe separator by default, but if you wanted to change that to say, double colons, simply use the function as follows:
This time, the generate HTML would output as follows:
Keeping the Array in a Functions File
If you sensibly include your functions in its own file and include the array in a configuration file, remember to add global $footerLinks;
so the array is available inside the function.