On page 74 of Web Designer magazine #130 is an article on making tag clouds in PHP. I suppose you could do it their way, but a few little things left me puzzled about their implementation, and I thought I would give it a go myself.
I'm a big, big fan of associative arrays in PHP. Most people who know arrays know that they are variables that contain a set of elements indexed by numerically, but PHP can index arrays in two ways. An associative array allows you to use a string key to identify each element of the array, rather than a number. The strings have to be unique, but for the purposes of creating a tag cloud, this is perfect because we only want to list each element once.
Using an associative array for the tags makes a huge difference in the amount of work you need to do. Using some smarts in other areas can offer some improvement, too. Let's step through the process and document it a bit to see how it goes....
more