parse($content); $artists = $artists[0][children]; $i=0; foreach ($artists as $artist) { $tags[$i]['tag_name'] = $artist[children][0][tagData]; $tags[$i]['tag_count'] = $artist[children][2][tagData]; $tags[$i]['tag_link'] = $artist[children][4][tagData]; $i++; } function tag_asort($tag1, $tag2){ if($tag1[tag_count] == $tag2[tag_count]){ return 0; } return ($tag1[tag_count] < $tag2[tag_count]) ? -1 : 1; } function tag_alphasort($tag1, $tag2){ if($tag1[tag_name] == $tag2[tag_name]){ return 0; } return ($tag1[tag_name] < $tag2[tag_name]) ? -1 : 1; } $tag_sizes = 8; usort($tags, "tag_asort"); if(count($tags) > 0) { // Start with the sorted list of tags and divide by the number of font sizes (buckets). // Then proceed to put an even number of tags into each bucket. The only restriction is // that tags of the same count can't span 2 buckets, so some buckets may have more tags // than others. Because of this, the sorted list of remaining tags is divided by the // remaining 'buckets' to evenly distribute the remainder of the tags and to fill as // many 'buckets' as possible up to the largest font size. $total_tags = count($tags); $min_tags = $total_tags / $tag_sizes; $bucket_count = 1; $bucket_items = 0; $tags_set = 0; foreach($tags as $key => $tag) { $tag_count = $tag[tag_count]; // If we've met the minimum number of tags for this class and the current tag // does not equal the last tag, we can proceed to the next class. if(($bucket_items >= $min_tags) and $last_count != $tag_count and $bucket_count < $tag_sizes) { $bucket_count++; $bucket_items = 0; // Calculate a new minimum number of tags for the remaining classes. $remaining_tags = $total_tags - $tags_set; $min_tags = $remaining_tags / $bucket_count; } // Set the tag to the current class. $tags[$key][tag_class] = 'tag'.$bucket_count; $bucket_items++; $tags_set++; $last_count = $tag_count; } usort($tags, 'tag_alphasort'); } //print foreach ( $tags as $artist ) { $thelist .= ''; $thelist .= $artist[tag_name] ." \n"; } echo $thelist; ?>