function printTagCloud($tags, $method='point') { //method above can be either point or area //point is typical tag cloud scaling //area scales tags approximately, such that *overall tag area* is proportional to the tag occurrences $max_area = 12000; $max_size = 55; // max font size in pixels $min_size = 12; // min font size in pixels $max_qty = max(array_values($tags)); $min_qty = min(array_values($tags)); $spread = $max_qty - $min_qty; if ($spread == 0) { // we don't want to divide by zero $spread = 1; } $step = ($max_size - $min_size) / ($spread); foreach ($tags as $key => $value) { if ($method == 'area') { $area = ($value / $max_qty) * $max_area; $size = sqrt((2*$area)/strlen($key)); } else if ($method == 'point') { $size = round($min_size + (($value - $min_qty) * $step)); } print '' . $key . ' '; } }